Skip to content

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

Open
@mjmg

Description

@mjmg

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions