GAM plotting using ggplot2
plotGAM(gamFit, smooth.cov, groupCovs = NULL, orderedAsFactor = T,
rawOrFitted = F, plotCI = T)fitted gam model as produced by mgcv::gam()
(character) name of smooth term to be plotted
(character) name of group variable to plot by, if NULL (default) then there are no groups in plot
if TRUE then the model is refitted with ordered variables as factors.
If FALSE (default) then only smooth terms are plotted; if rawOrFitted = "raw" then raw values are plotted against smooth; if rawOrFitted = "fitted" then fitted values are plotted against smooth
if TRUE (default) upper and lower confidence intervals are added at 2 standard errors above and below the mean
Returns a ggplot object that can be visualized using the print() function
Other Plotting: plotGAMM
data <- data.frame(x = rep(1:20, 2), group = rep(1:2, each = 20))
set.seed(1)
data$y <- (data$x^2)*data$group*3 + rnorm(40, sd = 200)
data$group <- ordered(data$group)
gam <- mgcv::gam(y ~ s(x) + group, data=data)
plot1 <- plotGAM(gamFit = gam, smooth.cov = "x", groupCovs = NULL,
rawOrFitted = "raw", plotCI=TRUE, orderedAsFactor = FALSE)
#> Warning: There are one or more factors in the model fit, please consider plotting by group since plot might be unprecise
gam <- mgcv::gam(y ~ s(x) + group + s(x, by=group), data=data)
plot2 <- plotGAM(gamFit = gam, smooth.cov = "x", groupCovs = "group",
rawOrFitted = "raw", orderedAsFactor = FALSE)