hey, can stacked bar plot resizing after filtering via legend be achieved using ggplotly?
Desired output is seen on the left side of the image.
library(ggplot2)
library(dplyr)
library(plotly)
# number of diamonds by cut and clarity (n)
cc <- count(diamonds, cut, clarity)
# number of diamonds by cut (nn)
cc2 <- left_join(cc, count(cc, cut, wt = n, name = 'nn')) %>%
mutate(prop = n / nn)
# plot is resizing (useful for comapring sum on remaining groups)
cc2 %>%
plot_ly(x = ~cut, y = ~prop, color = ~clarity) %>%
add_bars() %>%
layout(barmode = "stack")
# plot is not resizing
(cc2 %>%
ggplot(aes(cut, prop, fill = clarity)) +
geom_bar(stat = 'identity')
) %>% plotly::ggplotly()