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

guide_legend(reverse = TRUE) does not reverse legend order #2246

Open
simonsteiger opened this issue Mar 6, 2023 · 0 comments
Open

guide_legend(reverse = TRUE) does not reverse legend order #2246

simonsteiger opened this issue Mar 6, 2023 · 0 comments

Comments

@simonsteiger
Copy link

I reversed the legend order with guide_legend(reverse = TRUE), but the legend is unchanged in the plotly plot. The ggplot version is reversed.

library(plotly, warn=FALSE)
#> Loading required package: ggplot2

set.seed(123)

df <- data.frame(x = rnorm(10), y = rnorm(10), group = rep(c("A", "B"), times = 5))

p1 <- ggplot(df, aes(x = x, y = y, color = group)) +
  geom_line() +
  guides(color = guide_legend())
# Legend order default

# Plot with guides
p2 <- ggplot(df, aes(x = x, y = y, color = group)) +
  geom_line() +
  guides(color = guide_legend(reverse = TRUE))
# Legend order reversed

# Convert ggplot with reversed legend order
ggplotly(p2)
# Legend not reversed

Originally posted by @simonsteiger in #2234 (comment)

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

1 participant