Learn R Programming

pammtools (version 0.8.1)

gg_smooth: Plot smooth 1d terms of gam objects

Description

Given a gam model this convenience function returns a plot of its univariate smooth terms. If terms is not specified, all univariate smooths are plotted; otherwise only the requested ones (see get_terms for how terms are matched). Different smooths are faceted. Smooths that are indexed by a factor -- a factor by-variable or a factor-smooth interaction (bs = "fs"/"sz") -- are drawn in a single facet with one coloured/filled curve per factor level.

Usage

gg_smooth(x, ...)

# S3 method for default gg_smooth(x, fit, ...)

Value

A ggplot object.

Arguments

x

A data frame or object of class ped.

...

Further arguments passed to get_terms (e.g. terms).

fit

A model object.

See Also

get_terms

Examples

Run this code
g1 <- mgcv::gam(Sepal.Length ~ s(Sepal.Width) + s(Petal.Length), data=iris)
gg_smooth(iris, g1, terms=c("Sepal.Width", "Petal.Length"))
# all univariate smooths (terms omitted)
gg_smooth(iris, g1)
# factor-by smooth: one coloured curve per Species
g2 <- mgcv::gam(Sepal.Length ~ s(Sepal.Width, by = Species), data = iris)
gg_smooth(iris, g2, terms = "Sepal.Width")

Run the code above in your browser using DataLab