View source: R/convenience-plots.R
| gg_smooth | R Documentation |
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.
gg_smooth(x, ...)
## Default S3 method:
gg_smooth(x, fit, ...)
x |
A data frame or object of class |
... |
Further arguments passed to |
fit |
A model object. |
A ggplot object.
get_terms
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")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.