Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
mjmg opened this issue Dec 16, 2017 · 5 comments

Comments

@mjmg
Copy link

mjmg commented Dec 16, 2017

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

@cpsievert
Copy link
Collaborator

Will have to wait until plotly.js can support multiple legends -- plotly/plotly.js#1668

@henningsway
Copy link

Is there a way to avoid/ suppress the brackets, when combining the legends of two dimensions?

In my usecase it would be possible to paste two dimensions together e.g. fill and color.
fill would be "positive" or "negative" and the color would be some factorlabels: e.g. pos factor1 instead of (pos, factor1)?

@cgpu
Copy link

cgpu commented May 6, 2019

+1 Would also be interested in this feature. Even having the option to choose which one I want to choose would be a nicer option than the merge.

@jessicajturner
Copy link

Do you know if this has been fixed? I am still getting this error. If this has not been fixed, is there a way to work around it by using something other than ggplot or plotly?

@WhyBeeYes
Copy link

I think this issue is addressed in #572. The solution is to use aes outside geom for unwanted legends if the program is run in R Studio. In R Shiny, use style() function on the plotly object, as using the aes outside merges the legends together.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants