Learn R Programming

gratia (version 0.9.0)

smooth_label: Extract the label for a smooth used by 'mgcv'

Description

The label 'mgcv' uses for smooths is useful in many contexts, including selecting smooths or labelling plots. smooth_label() extracts this label from an 'mgcv' smooth object, i.e. an object that inherits from class "mgcv.smooth". These would typically be found in the $smooth component of a GAM fitted by mgcv::gam() or mgcv::bam(), or related functions.

Usage

smooth_label(object, ...)

# S3 method for gam smooth_label(object, id, ...)

# S3 method for mgcv.smooth smooth_label(object, ...)

Value

A character vector.

Arguments

object

an R object. Currently, methods for class "gam" and for mgcv smooth objects inheriting from class "mgcv.smooth" are supported.

...

arguments passed to other methods.

id

numeric; the indices of the smooths whose labels are to be extracted. If missing, labels for all smooths in the model are returned.

Examples

Run this code
load_mgcv()
df <- data_sim("gwf2", n = 100)
m <- gam(y ~ s(x), data = df, method = "REML")

# extract the smooth
sm <- get_smooths_by_id(m, id = 1)[[1]]

# extract the label
smooth_label(sm)

# or directly on the fitted GAM
smooth_label(m$smooth[[1]])

# or extract labels by idex/position
smooth_label(m, id = 1)

Run the code above in your browser using DataLab