Skip to content

legend.position always 'right' in ggplotly, except when legend.position = 'none' #1049

Open
@d4tagirl

Description

@d4tagirl

When plotting a ggplot object using ggplotly, legend.position is always 'right' even if I chose legend.position = 'top' or any of the other options. It only works as it is supposed to when I specify legend.position = 'none' that it actually disappears.

ggplot displays the legend fine.

library(tibble)
library(ggplot2)

df <- tibble(year = c(2000, 2001, 2000, 2001),
             freq = c(3, 4, 2, 9),
             clas = c("A", "A", "B", "B"))

ggplot(df, aes(year, freq, color = clas)) +
  geom_line() +
  theme(legend.position = 'top')

When I try this instead:

library(plotly)

ggplotly(
ggplot(df, aes(year, freq, color = clas)) +
  geom_line() +
  theme(legend.position = 'top')
)

I get the legend on the right, as I show in this shiny app.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions