Map density to fill not colour
alanocallaghan opened this issue · 2 comments
Would be very cool to be able to set pch=21 and then map the point fill to density. Perhaps this is obvious but not to me. I tried
ggplot(mtcars) + geom_pointdensity(shape = 21, aes(mpg, cyl, fill=stat(density)))
But I get
Error: Aesthetics must be valid computed stats. Problematic aesthetic(s): fill = stat(density).
Did you map your stat in the wrong layer?
In the CRAN version of the package, the stat is called "n_neighbors" and not "density", so I think that's why your code is not working.
In the never dev version of the package I renamed the stat from n_neighbors to density (cause it's a more obvious choice as demonstrated by this whole issue :D ) and your code works just fine. So the easiest solution is to update to the dev version of the package like this: remotes::install_github("LKremer/ggpointdensity")
.
Alternatively you can also keep the CRAN version of the package and try to use stat(n_neighbors)
, but I haven't tested this solution.
Missed this solution, thanks!