Skip to content

Boxplot legends #345

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

Closed
cpsievert opened this issue Dec 13, 2015 · 2 comments
Closed

Boxplot legends #345

cpsievert opened this issue Dec 13, 2015 · 2 comments

Comments

@cpsievert
Copy link
Collaborator

I'm not convinced we can/should provide legends for boxplots (see also #230). As far as I know, you can't draw multiple boxes in a single trace, so there must be a legend entry for unique x, making the legend redundant. For example, we could provide a legend for something like this:

library(plotly)
dat <- data.frame(
  cond = factor(rep(c("A", "B", "C", "D"), each = 200)), 
  col = factor(rep(c("C1", "C2"), each = 400)), 
  rating = c(rnorm(200), rnorm(200, mean = .8), rnorm(200, mean = .4), rnorm(200, mean = .2))
)
ggplot(dat, aes(x=cond, y=rating)) + 
  geom_boxplot(aes(fill=cond))

rplot01

It'd be more useful to have a legend when color/fill is nested in x, but I don't think we could do something like this in plotlyjs, right @chriddyp?

ggplot(dat, aes(x=cond, y=rating)) + 
  geom_boxplot(aes(fill=col))

rplot

@cpsievert
Copy link
Collaborator Author

@chriddyp
Copy link
Member

hey @cpsievert - actually you can. Here's an example: https://plot.ly/~patsy.cline/35.embed. You have to include an x value for every single y value, i.e.:

{
    "x": [1, 1, 1],
    "y": [2, 1, 5]
}

Or, with multiple boxes (same trace so same color and same legend entry)

{
    "x": [1, 1, 1, 2, 2, 2],
    "y": [2, 1, 5, 3, 1, 5]
}

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

No branches or pull requests

2 participants