ggplot2: Set alpha=0 for certain points depending on fill value ggplot2: Set alpha=0 for certain points depending on fill value r r

ggplot2: Set alpha=0 for certain points depending on fill value


Another possibility, just using ifelse instead of cut.

d + stat_density2d(geom="tile",     aes(fill = ..density.., alpha = ifelse(..density.. < 1e-5, 0, 1)),     contour = FALSE) + scale_alpha_continuous(range = c(0, 1), guide = "none")

enter image description here


This seems to work:

d + stat_density2d(geom="tile",      aes(fill = ..density..,      alpha=cut(..density..,breaks=c(0,1e-5,Inf))),      contour = FALSE)+ scale_alpha_manual(values=c(0,1),guide="none")

enter image description here