plotly / plotly/plotly.R

ggplotly only displays one legend

Open
#2,254 1 comment 0 reactions 0 assignees View on GitHub

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")

ggplot_output
ggplotly_output

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.