`guide_legend(reverse = TRUE)` does not reverse legend order
Open
Nobody has claimed this yet.
- Dominant language
- R
- Stars
- 2.7k
- Forks
- 641
- PR merge metrics
- No merged PRs in 30d
Description
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 https://github.com/plotly/plotly.R/issues/2234#issuecomment-1457010264
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by running the supplied R example and comparing the ggplot legend with the result of ggplotly(p2). Trace the ggplotly conversion path for guide_legend(reverse = TRUE), then verify that the converted plot preserves the reversed legend order.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- r
- Domain
- data-visualization
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100