rsrjohnson
rsrjohnson

Reputation: 120

Adding a general title to autoplot.lm

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.

Upvotes: 3

Views: 2437

Answers (2)

Z.Lin
Z.Lin

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

plot

Upvotes: 5

koki25ando
koki25ando

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

Related Questions