Say, I have a GAM that looks like this:
# Load library
library(mgcv)
# Load data
data(mtcars)
# Model for mpg
mpg.gam <- gam(mpg ~ s(hp) + s(wt), data = mtcars)
Now, I'd like to plot the GAM using ggplot2
. So, I use plot.gam
to produce all the information I need, like this:
foo <- plot(mpg.gam)
This also generates an unwanted figure. (Yes, I realise that I'm complaining that a plotting function plots something...) When using visreg
in the same way, I'd simply specify plot = FALSE
to suppress the figure, but plot.gam
doesn't seem to have this option. My first thought was perhaps invisible
would do the job (e.g., invisible(foo <- plot(mpg.gam))
), but that didn't seem to work. Is there an easy way of doing this without outputting the unwanted figure to file?