I used the ggarrange() function in R to create a combined plot with two plots generated from ggplot2 like follows:
library(ggpubr)
plotfn <- function(){
disp_hist_ggplot1 <- ggplot(mtcars, aes(disp)) + geom_histogram()
disp_hist_ggplot2 <- ggplot(mtcars, aes(disp)) + geom_histogram()
disp_hist_combine <- ggarrange(disp_hist_ggplot1, disp_hist_ggplot2, ncol=2, nrow=1)
return (disp_hist_combine)}
p <- plotfn()
p
Now, the "disp_hist_combine" contains a plot class as "[1] "gg" "ggplot" "ggarrange"", but I want to dissemble it and get the two individual ggplot object again from the disp_hist_combine. How can I get it? Is there any functions that can recover the ggplot from the ggarrange ?
I just wrap the code into a function. Now I just want to find a unit test method to test the function plotfn(). Testthat doesn't work any more on the class of ("gg" "ggplot" "ggarrange"").