ggplotly only displays one legend
Open
Nobody has claimed this yet.
- Dominant language
- R
- Stars
- 2.7k
- Forks
- 641
- PR merge metrics
- No merged PRs in 30d
Description
While ggplot produces legends for each aesthetic (other than x & y), after calling ggplotly on the result, only one legend remains (although both titles display).
library(tidyverse)
library(gapminder)
library(plotly)
p <- gapminder %>%
filter(year == 2007) %>%
mutate(pop_m = pop / 1000000) %>%
ggplot(aes(x = gdpPercap, y = lifeExp, colour = continent, size = pop_m, text = country)) +
geom_point() +
scale_x_log10(label = scales::comma) +
scale_size_continuous(label = scales::comma, breaks = c(0, 1, 10, 100, 1000), range = c(1, 10)) +
labs(x = "GDP per capita ($)", y = "Life expectancy (years)", size = "Population, millions", colour = "Continent")
p
ggplotly(p, tooltip = "text")


I don't think this "disappearing legend" problem is a duplicate amongst the issues I've reviewed, but there is some discussion of this on StackOverflow.
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 reproducible R example in the issue and compare the ggplot and ggplotly outputs, including the colour and size legends. Trace the ggplotly conversion path responsible for legends; done means both legends remain visible with their titles and scales after conversion.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- r
- Domain
- data-visualization
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100