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

Option to keep original order #3457

Closed
xmarti6 opened this issue Jul 26, 2019 · 1 comment
Closed

Option to keep original order #3457

xmarti6 opened this issue Jul 26, 2019 · 1 comment
Labels
feature a feature request or enhancement scales 🐍

Comments

@xmarti6
Copy link

xmarti6 commented Jul 26, 2019

Hi, I know this is an old topic, but just was wondering if it would be feasiable to add a ggplot option to just keep input order (e.g. ko=T). ggplot is widely used within other packages and sometimes is kind of cumbersome to be playing around with factors and levels to keep input data. Would that option have wide colateral effects?

Many thanks

@thomasp85 thomasp85 added feature a feature request or enhancement layers 📈 scales 🐍 and removed layers 📈 labels Jan 21, 2020
@teunbrand
Copy link
Collaborator

There are plenty of options to preserve the original order, such as setting factor levels and setting limits.

library(ggplot2)

df <- data.frame(x = c("B", "A", "C"), y = 1:3)

ggplot(df, aes(forcats::fct_inorder(x), y)) +
  geom_col()

f <- function(x) factor(x, as.character(unique(x)))

ggplot(df, aes(f(x), y)) +
  geom_col()

ggplot(df, aes(x, y)) +
  geom_col() +
  scale_x_discrete(limits = unique(df$x))

Created on 2024-09-12 with reprex v2.1.1

If there a deeper need to preserve orders, then this should be solved in the {scales} package, where range training should then preserve order:

x <- scales::DiscreteRange$new()
x$train(c("B", "A", "C"))
x$range
#> [1] "A" "B" "C"

Created on 2024-09-12 with reprex v2.1.1

If {scales} decides to allow this option, we can re-open the issue.

@teunbrand teunbrand closed this as not planned Won't fix, can't repro, duplicate, stale Sep 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature a feature request or enhancement scales 🐍
Projects
None yet
Development

No branches or pull requests

3 participants