Feature request for transparency
MxNl opened this issue · 1 comments
MxNl commented
I think it would be nice to have an argument in geom_pointdensity
that allows to set the alpha
value depending on the point density. Could you implement that? Thanks a lot for this package!
LKremer commented
Hi @MxNl ,
sorry for the late reply, I did not see this issue. This is already possible by using ggplot2's after_stat
function. Maybe I should add a short example to the docs. For now, here is a minimal example:
library(ggplot2)
library(dplyr)
library(viridis)
library(ggpointdensity)
dat <- bind_rows(
tibble(x = rnorm(7000, sd = 1),
y = rnorm(7000, sd = 10),
group = "foo"),
tibble(x = rnorm(3000, mean = 1, sd = .5),
y = rnorm(3000, mean = 7, sd = 5),
group = "bar"))
ggplot(data = dat, mapping = aes(x = x, y = y, alpha = after_stat(density))) +
geom_pointdensity() +
scale_color_viridis()
after_stat()
allows you to use the density calculated by the geom_pointdensity
(or rather stat_pointdensity
internally). If you want to learn more, check out this part of the ggplot2 docs: aes_eval