3

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)

enter image description here 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.

rsrjohnson
  • 100
  • 1
  • 8

2 Answers2

5

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")

plot

Z.Lin
  • 28,055
  • 6
  • 54
  • 94
0

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.

koki25ando
  • 74
  • 6
  • Thank you for your quick answer. I'm sorry for not mentioning but I already tried grid.arrange() getting this error: Error in $<-(*tmp*, wrapvp, value = vp) : no method for assigning subsets of this S4 class. – rsrjohnson Apr 27 '19 at 15:55