legend.position always 'right' in ggplotly, except when legend.position = 'none'
Nobody has claimed this yet.
- Dominant language
- R
- Stars
- 2.7k
- Forks
- 641
- PR merge metrics
- No merged PRs in 30d
Description
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.
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 with the reproducible R example using ggplotly, ggplot2, tibble, and theme(legend.position = 'top'), then compare the rendered legend position with the ggplot output. Done means ggplotly honors top and other supported legend positions while still hiding the legend for legend.position = 'none'.
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
- 35/100