Reputation: 120
I'm plotting diagnostics plots for a regression model using autoplot. I would like to add a general single title for the graph.
As example:
library(ggfortify)
autoplot(lm(Petal.Width ~ Petal.Length, data = iris), label.size = 3)
I would like to place a "Title" at the top without modifying any subplot. Thanks in advance.
EDIT: I already tried grid.arrange() getting this error: Error in $<-(tmp, wrapvp, value = vp) : no method for assigning subsets of this S4 class.
Upvotes: 3
Views: 2437
Reputation: 29085
You can directly reference the list of ggplot objects within the ggmultiplot
object returned by ggfortify
's autoplot.lm
:
p <- autoplot(lm(Petal.Width ~ Petal.Length, data = iris), label.size = 3)
gridExtra::grid.arrange(grobs = p@plots, top = "some title")
Upvotes: 5
Reputation: 74
How about using gridExtra
& grid
packages?
library(gridExtra)
library(grid)
title1=textGrob("Title", gp=gpar(fontface="bold"))
grid.arrange(plot1, plot2, plot3, plot4,
top=title1)
I would write codes like this.
Upvotes: 0