Reputation: 5089
I'm producing a tesselation of random points within a heart shape, I'm having a difficult time figuring out how to control the color of the pixels in the plot. I thought as plot(tess)
(in this example) produces a plot of image values, I would be able to control them by just specifying the same number of colors in the color ramp, but that is not the case.
library(spatstat)
t <- seq(from = 2*pi, to = 0.001, length.out = 1500)
x <- 16*sin(t)**3
y <- 13*cos(t) - 5*cos(2*t) - 2*cos(3*t) - cos(4*t) #heart equation taken from wolfram http://mathworld.wolfram.com/HeartCurve.html.
heart_win <- owin(poly = cbind(x,y)) #note - not self enclosed
#random sample of points within heart
points <- rpoint(100, win = heart_win)
tess <- dirichlet(points)
plot(tess, main = ' ')
#color for 100 values
norm_palette <- colorRampPalette(c("white","red"))
plot(tess, main = ' ', col=norm_palette(100), valuesAreColours = FALSE)
Which produces this image below:
Yes I'm that guy that doesn't make his wife a valentines day gift till the day of (don't judge me)!
Upvotes: 1
Views: 463
Reputation: 2407
You are not calling the resulting image in the tess object. Just change your plot call to:
plot(tess$image, main="", col=colorRampPalette(c("white","red"))(tess$n), valuesAreColours=FALSE)
Upvotes: 2
Reputation: 121588
Even I don't give a gift to my wife and I will not give a gift today , you can try this :
plot(tess$image,col=norm_palette(100))
Upvotes: 2