I wonder how can I reorder bar plot in ggplotly using only bars that belong to the groups I selected from the legend
Having DF with many Observations that comes from several groups, I made geom_bar that shows the top 20 Observations ordering DESC by their y values with fill = Group, if I choose from the legend to show only part of the groups I wish to get the top 20 Observations from the selected groups
ggplotly(ggplot(DF %>%arrange(desc(y)) %>%
slice(1:20) , aes(x = reorder(Obs, -y), y = y)) +
geom_bar(aes(x = reorder(Obs, -y),y = y, fill = Group)), stat = "identity", width = 0.8)
Hope I understood well: