ggplotly() creates a wrong legend in some cases
Open
Nobody has claimed this yet.
- Dominant language
- R
- Stars
- 2.7k
- Forks
- 641
- PR merge metrics
- No merged PRs in 30d
Description
Given
library(ggplot2)
library(plotly)
d1 <- data.frame(X=1:10, Y= (1:10)^2, b=paste0("B",1:10),d="d1")
d1$Y2 <- d1$Y+2
gg2 <- ggplot(data=d1, aes(label=b)) +
geom_point(aes(x=X, y=Y, col="blue")) +
geom_line(aes(x=X, y=Y2, col="orange")) +
scale_color_manual(values=c("blue","orange"),
labels=c("Left","Center"),
name="")
print(gg2) results in:
But
ggplotly(gg2)
results in:
I know a more conventional code such as:
d1 <- data.frame(X=1:10, Y= (1:10)^2, b=paste0("B",1:10),position="left")
d2 <- data.frame(X=1:10, Y= (1:10)^2 + 2, b=paste0("B",1:10),position="center")
d <- rbind(d1,d2)
gg2 <- ggplot(data=d, aes(label=b)) +
geom_point(data=d[d$position=="left",],aes(x=X, y=Y,col=position)) +
geom_line(data=d[d$position=="center",],aes(x=X, y=Y,col=position)) +
scale_color_manual(values=c("blue","orange","red"),
labels=c("Left","Center"),
name="")
gg2
ggplotly(gg2)
results in similar legends, but I wonder if the 1st example is not uncovering a bug in ggplotly()
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 from the issue and compare the ggplot2 and ggplotly legends. Investigate the ggplotly conversion of manual colour scales and verify that the converted legend matches the declared Left and Center labels without extra entries.
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