I have to use gridExtra::grid.arrange for plotting several plot besides eachother because of the package I am using to create the fit for the plot. I have to create a title for the plot using grid.arrange. Now I want to combine the two, but cannot figure out how. So: I want to plot several figures besides eachother and give them all have a different title.
I have euler1 and euler2 as fits tat represent my data in an euler diagram. for plotting 2 plots besides eachother this code works for me:
gridExtra::grid.arrange(plot(euler1),plot(euler2))
for giving a single plot a title, this code works for me:
plot1 <- plot(euler1)
grid.arrange(grobs = list(plot1), top = "Title 1")
Now, I would like to combine the two codes. How can I do it?
I tries for example (but doesn't work):
plot1 <- plot(euler1)
plot2 <- plot(euler2)
gridExtra::grid.arrange(plot1, plot2, grobs = list(plot1, plot2), top = list("Title 1","Title 2"))
Kinds regards, Judith
Typically you'd add titles to the plot themselves, as in
p1 = ggplot() + ggtitle('plot 1')
p2 = ggplot() + ggtitle('plot 2')
grid.arrange(grobs = list(p1, p2), top = "Global Title", ncol=2)
but if you prefer to use grid.arrange's top
argument for the titles, you can nest them,
p = ggplot()
grid.arrange(arrangeGrob(p, top = 'title 1'), arrangeGrob(p, top = 'title 2'), top = "Global Title", ncol=2)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With