Skip to content

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

Open
@simonsteiger

Description

@simonsteiger

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions