plotly / plotly/plotly.R

ggplotly unable to handle multiple legends properly in layered charts generated by ggplot2

Open
#1,164 5 comments 7 reactions 0 assignees View on GitHub

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)
  1. Multiple legend titles are clustered together
  2. Multiple legends are not separated
  3. There is extra text ",1" in legend labels

This is the ggplot2 output:
image

This is the ggplotly output:
newplot

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.