Order of points
Mchicken1988 opened this issue · 3 comments
I am wondering if there is a way to re-order the points according to their density/n_neighbors. Often points with high-density are hidden behind points with lower density. Plots would look much "cleaner" if there would be a way to order points by increasing density. However, if I remember it correctly the order is pre-determined by the order within the underlying dataframe.
This is already possible now, using staged aesthetic mappings:
library(ggplot2)
ggplot(iris, aes(x = Sepal.Width, y = Sepal.Length)) +
ggpointdensity::geom_pointdensity(aes(color = after_stat(ndensity)), size=8) +
NULL
ggplot(iris, aes(x = Sepal.Width, y = Sepal.Length)) +
ggpointdensity::geom_pointdensity(aes(x= stage(Sepal.Width, after_stat = x[order(ndensity)]), y=stage(Sepal.Length, after_stat = y[order(ndensity)]), color = after_stat(sort(ndensity))), size=8) +
NULL
Created on 2023-12-04 with reprex v2.0.2
But it might indeed be a good idea to make this the default. Although I like being able to control plotting order by data order, since a user could still control plotting ordering using above technique, I am in favor of this FR.
I think this would be good as a default because it's pretty tricky to remember how to do this manually.