Ggplotly does not always make a legend correctly for where there are points and lines
Nobody has claimed this yet.
- Dominant language
- R
- Stars
- 2.7k
- Forks
- 641
- PR merge metrics
- No merged PRs in 30d
Description
Ggplotly does not always make a legend correctly for where there are points and lines. Sometimes it only makes the legend key based on either geom_point or geom_line, whichever is the first layer. Below is an example where it doesn't work. It seems to fix it if the data is arranged by the x variable. It'd be good if it worked for however the data was arranged.
library(dplyr)
library(ggplot2)
library(plotly)
#This doesn't work: the legend is based only on the first geom shape
plot_data <- iris %>%
as_tibble() %>%
janitor::clean_names()
plot <- ggplot(data = plot_data, aes(petal_width, petal_length, col = species)) +
geom_point() +
geom_line()
plotly::ggplotly(plot)

plot_data <- iris %>%
as_tibble() %>%
janitor::clean_names() %>%
arrange(petal_width)
plot <- ggplot(data = plot_data, aes(petal_width, petal_length, col = species)) +
geom_point() +
geom_line()
plotly::ggplotly(plot)

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 reproducing the supplied R example with plotly::ggplotly, comparing the unsorted iris data with the version arranged by petal_width. The issue is done when the legend correctly represents both point and line layers regardless of the data row order.
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
- 35/100