ggplotly unable to handle multiple legends properly in layered charts generated by ggplot2
Open
Nobody has claimed this yet.
ggplotly
plotly.js
- Dominant language
- R
- Stars
- 2.7k
- Forks
- 641
- PR merge metrics
- No merged PRs in 30d
Description
From the example in http://bxhorn.com/legends-ggplot/#managing-multiple-legends-in-a-layered-chart
# Multiple Legends
# load data
data(diamonds)
# calc quantiles with specified probabilities
new.prob <- c(0.90, 0.95, 0.99)
cut.probs <- plyr::ddply(diamonds, .(cut), numcolwise(quantile, probs = new.prob))[, c("cut", "price")]
cut.probs <- transform(cut.probs, quantile = c("P90", "P95", "P99"))
# layered graph
gg<-ggplot(diamonds, aes(cut, price)) +
geom_boxplot(aes(fill = factor(cut))) +
geom_point(data = cut.probs, aes(cut, price, color = factor(quantile)), size = 5) +
scale_fill_discrete(name = "Quality of the Cut") +
scale_color_discrete(name = "My Quantiles")
gg
plotly::ggplotly(gg)
- Multiple legend titles are clustered together
- Multiple legends are not separated
- There is extra text ",1" in legend labels
This is the ggplot2 output:

This is the ggplotly output:

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 supplied layered ggplot2 example and the ggplotly(gg) entry point, comparing its output with the ggplot2 output. Trace how the two aesthetics and their scale names become legends. Done means the titles are separated, the legends are distinct, and the extra ",1" text is absent.
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