-1

I have a point pattern (ppp) which I have done a kernel density estimation on. I have already changed the colour output using this:

require(RColorBrewer) colfunc <- colorRampPalette(c("white", "black"))

Then created the kernel density map (smktppp and W were previously specified):

plot(density.ppp(smktppp, 0.5, edge=T), col=colfunc, main="Supermarket Density", window=W)

Here is my output

I would like to make the white parts (where the KDE/scale is at 0) transparent (with no fill). How would I go about doing this?

Thank you!

  • Most plotting routines will leave NA values blank or "transparent". There's also sometime recognition of a value: "transparent". After looking at your plot I'm trying to figure out (without success) what difference you would expect when you made these changes? – IRTFM Feb 25 '17 at 19:33
  • The 0 values are not NA values though. It'd like to do this with three plots and then overlay them to create a map showing combined density. I can't do this at the moment as the white values on the next plot replace colored values in the first. – skyandbuildings Feb 25 '17 at 19:39
  • So have you tried the now blindingly obvious: `colorRampPalette(c("transparent", "black"))(5)`? (Do read the help page for whatever plot function handles the `ppp`-class to see if it supports transparency, although that is usually a metter for the device to decide.) – IRTFM Feb 25 '17 at 19:47
  • This seems related to your other question http://stackoverflow.com/q/42459424/3341769 which I tried to answer. Does this solve this problem also? If not I have given a short answer below. – Ege Rubak Feb 26 '17 at 10:20

1 Answers1

0

If you replace pixel values by NA these will not be plotted and hence work as transparent. E.g.

smktim  <- density.ppp(smktppp, 0.5, edge=T)
smktim[smktim<1e-7] <- NA
Ege Rubak
  • 4,347
  • 1
  • 10
  • 18