# \donttest{
library(mgcv)
# Fit a GAM model
data(mtcars)
mtcars$cyl <- factor(mtcars$cyl) # Convert to factor before fitting GAM
model <- gam(mpg ~ s(hp) + s(wt) + cyl, data = mtcars)
# Plot effect of hp (with other variables at median)
plot_gam(model, "hp")
# Plot effect of hp (with other variables at 25th percentile)
plot_gam(model, "hp", quantile.others = 25)
# Customize plot
plot_gam(model, "hp", main = "Effect of Horsepower", col = "blue", lwd = 2)
# }
Run the code above in your browser using DataLab