Arranging plots together that are not all ggplots

I have two plots that I would like to arrange together. One is made using ggpot2 and the other was made using the BAMMdata package. What package can I use to arrange them together as I understand that patchwork() only works on ggplots?

did you try the cowplot package

library(cowplot)
plot_grid(p1, p2, ncol=1, align="v")

For one of my graphs (shown below) I have been unable to assign it to a value (e.g. p1 or p2) and therefore have been unable to use cowplot. Is there any way to get this to work?

plotRateThroughTime(m_subtree, ratetype="speciation", avgCol="steelblue", ylim=c(0, 0.5), cex.axis=0.7, intervalCol="steelblue", intervals=c(0.05, 0.95), opacity=0.1, cex.lab=1.0)

the trick is to use recordPlot()
also cowplot will need gridGraphics installed.

library(BAMMtools)
data(events.whales)
data(whales)
ephy <- getEventData(whales,events.whales)

plotRateThroughTime(ephy)
p1 <- recordPlot()

library(ggplot2)
p2 <- iris |> ggplot()+aes(x=Species,y=Petal.Length)+geom_boxplot()

library(cowplot)
library(gridGraphics)
plot_grid(p1, p2, labels = c('A', 'B'))

1 Like

Thank you! This has worked perfectly

How do I make two graphs in cowplot (arranged side by side) different heights? I understand I can't use rel_height as this only works if the are on top of each other

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.