Home > Net >  ggplotly stacked bar chart not resizing after filtering
ggplotly stacked bar chart not resizing after filtering

Time:11-16

For some reason when producing a plotly graph with the ggplotly function, the filtering does not seem to resize the y-axis. The filtered portion are simply removed, while yaxis stays at it's original length. Please see this example:

library(plotly)
library(ggplot2)
library(dplyr)

lab <- paste("Vertical Label", c(1, 2, 3, 4, 5))

ds <- data.frame(x = sample(lab, size = 1000, replace = T),
                 y = sample(LETTERS[1:5], size = 1000, replace = T)) %>%
      group_by(x,y) %>% summarise(count= n())

ggplotly(
ggplot(ds, aes(x = x,y=count, fill = y))  
  geom_col()  
  theme(axis.text.x = element_text(angle = 90)) 
)

enter image description here

Same approach with plot_ly function works. However, I needed similar results with ggploty

plot_ly(ds, x = ~x, y = ~count, type = 'bar', color = ~y
        ) %>% layout(title = "Vertical Axis Lables",
                      xaxis = list(title = ""),
                      yaxis = list(title = ""), barmode = 'stack')

enter image description here

I couldn't find anything helpful in stack overflow or google. Just came across an incomplete answer here: Filtered plot

  • Related