Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Order of points #15

Open
Mchicken1988 opened this issue Sep 29, 2020 · 3 comments
Open

Order of points #15

Mchicken1988 opened this issue Sep 29, 2020 · 3 comments

Comments

@Mchicken1988
Copy link

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.

@jan-glx
Copy link
Contributor

jan-glx commented Dec 4, 2023

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.

@Aariq
Copy link

Aariq commented Feb 8, 2024

I think this would be good as a default because it's pretty tricky to remember how to do this manually.

@mattgalbraith
Copy link

+1 for ordering by density as default

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants