I need help with generating dropdown menu for plots generated in ggplot. (As shown in here: https://plotly.com/r/dropdowns/)
I have generated a number of plots using ggplot as shown below:
da1 <- ggdensity(data=data, x=data$x_1, add = "mean", rug=TRUE, color="Status", palette = c("#00BFC4", "#F8766D"), ylab="Area 1", xlab="") +
theme(plot.title = element_text(hjust = 0.5),
legend.position="none")
da2 <- ggdensity(data=data, x=data$x_2, add = "mean", rug=TRUE, color="Status", palette = c("#00BFC4", "#F8766D"), ylab="Area 2", xlab="") +
theme(plot.title = element_text(hjust = 0.5),
legend.position="none")
a1 <- ggplot(data=data, aes(x=Status, y=data$x_1, fill=Status, label=data$label)) +
geom_violin() +
geom_point(alpha=0.6, size=3) +
stat_compare_means(method="wilcox.test", aes(label = ..p.signif..), size=7, label.x = 1.5, vjust=0.5) +
theme(text = element_text(colour = "black"),
axis.title.x = element_text(size=14, face="bold"),
axis.title.y = element_text(size=14, face="bold"),
legend.position="none") +
xlab("") +
ylab("")
a2 <- ggplot(data=data, aes(x=Status, y=data$x_2, fill=Status, label=data$label)) +
geom_violin() +
geom_point(alpha=0.6, size=3) +
stat_compare_means(method="wilcox.test", aes(label = ..p.signif..), size=7, label.x = 1.5, vjust=0.5) +
theme(text = element_text(colour = "black"),
axis.title.x = element_text(size=14, face="bold"),
axis.title.y = element_text(size=14, face="bold"),
legend.position="none") +
xlab("") +
ylab("")
ga1 <- ggplotly(a1, tooltip=c("label", "y", "x"))
ga2 <- ggplotly(a2, tooltip=c("label", "y", "x"))
I then created subplots for the plots:
fig <- subplot(da1, da2)
fig2 <- subplot(ga1, ga2)
I would like to create a dropdown menu where a choice between Fig and Fig2 is shown and that the plots change when chosen specific option.
I scoured through stackoverflow but I couldn't find anyone doing the dropdown menus with ggplots. The closest answer I found was here Generating Dropdown menu for Plotly charts but the response doesn't make sense in my head. Would anybody be so kind in helping me with this issue - I want to stay using ggplots generated wiht the method I have shown above.