1

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:

enter image description here

Yes I'm that guy that doesn't make his wife a valentines day gift till the day of (don't judge me)!

Andy W
  • 5,031
  • 3
  • 25
  • 51

2 Answers2

2

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))

enter image description here

agstudy
  • 119,832
  • 17
  • 199
  • 261
2

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)
Jeffrey Evans
  • 2,325
  • 12
  • 18
  • Ahh thank you! And thanks to agstudy to (near simultaneous answers as far as I can tell). I will mark yours as answered simply to spread the reputation wealth around. – Andy W Feb 14 '13 at 15:54
  • @AndyW yes ! and +1 for this the wealth of R reputation( even I beat him by few seconds :) – agstudy Feb 14 '13 at 15:57