Skip to content

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

Open

Description

@doug-friedman

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!

Activity

  1. changed the title [-]Custom ggplot2 boxplot doesn't work ggplotly[/-] [+]Custom dimensions for a ggplot2 boxplot doesn't work with ggplotly[/+] on Aug 10, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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