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
Best Answer
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)
I figured out how to do it, since the use of main
in plot
was fixed for the eulerr package. Now I can use:
gridExtra::grid.arrange(plot(euler1, main = 'title1'),plot(euler2, main = 'title2'))
Thanks everyone for the feedback.