Black Lives Matter. Please consider donating to Black Girls Code today.
Learn how to use COVID-19 data in open source Dash apps. Register for the Sept 23rd webinar with IQT!

R plotly ggplot2: Remove placeholders when removing middle bars in geom_bar

Hello everyone,

I am using the example from the plotly page to generate a bar plot. I am also using plotly devel version 4.2.0.

Code:

library(plotly)

df <- data.frame(x = as.factor(LETTERS[1:5]), 
                 y = sample(10:20, size = 5))

# First change factor levels
df$x <- factor(df$x, levels = c("C", "B", "A", "D", "E"))

# Plot
p <- ggplot(df, aes(x, y, fill = x)) + 
  geom_bar(stat = "identity") +
  ggtitle("Bar Chart with changed factor levels")

ggplotly(p)

My session info:

R version 3.3.0 (2016-05-03)
Platform: x86_64-apple-darwin13.4.0 (64-bit)
Running under: OS X 10.11.5 (El Capitan)

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] plotly_4.2.0         ggplot2_2.1.0        BiocInstaller_1.23.6

On the plot.ly page, when I click on one of the bars in the middle (blue/green) the plot gets autoscaled and the placeholders for the missing bars disappear. But when I generate the plot using the code in R and click on the middle bars, the placeholders are still there. How can I remove the placeholders when removing bars from the middle?

Thanks,
Komal