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

Custom dimensions for a ggplot2 boxplot doesn't work with ggplotly #1098

Open
doug-friedman opened this issue Aug 10, 2017 · 0 comments
Open

Comments

@doug-friedman
Copy link

doug-friedman commented Aug 10, 2017

When I create a ggplot2 boxplot with custom dimensions (see the bottom of http://ggplot2.tidyverse.org/reference/geom_boxplot.html#examples), plotly doesn't render the boxplot when I apply ggplotly. However, it works ok with a traditional boxplot where the dimensions are calculated by geom_boxplot/stat_boxplot.

Below is a reproducible example of the issue.

## Libraries
library(ggplot2)
library(plotly)

## Using fake data with extreme values
fake_data = data.frame(
  y1 = c(rnorm(100, 2, 3), rnorm(10, 10, 15))
)


# ggplot2
g1 = ggplot(data=fake_data, aes(x ="cat1", y= y1)) + 
  #stat_boxplot(geom="errorbar") +
  geom_boxplot() +
  labs(title="Traditional Boxplot") +
  ylim(c(-5, 25))

g1

quants = quantile(fake_data$y1, c(0.05, .25, .5, .75, .95))
q_df = data.frame(t(quants))
names(q_df) = c("y5", "y25", "y50", "y75", "y95")


g2 = ggplot(data=q_df, aes(x ="cat1")) + 
  #stat_boxplot(geom="errorbar") +
  geom_boxplot(stat="identity", aes(, 
       ymin = y5, lower = y25, 
       middle = y50, upper = y75,
       ymax = y95)) +
  geom_point(data=subset(fake_data, (y1 > q_df$y95) | (y1 < q_df$y5)), aes(y=y1)) +
  labs(title="5%/95% Boxplot") +
  ylim(c(-5, 25))

g2



# plotly
plotly::ggplotly(g1)
plotly::ggplotly(g2) # DOESN'T WORK!
@doug-friedman doug-friedman changed the title Custom ggplot2 boxplot doesn't work ggplotly Custom dimensions for a ggplot2 boxplot doesn't work with ggplotly Aug 10, 2017
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

2 participants