Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

draw.penalty_df

Display penalty matrices of smooths using ggplot


Description

Displays the penalty matrices of smooths as a heatmap using ggplot

Usage

## S3 method for class 'penalty_df'
draw(
  object,
  normalize = FALSE,
  continuous_fill = NULL,
  xlab = NULL,
  ylab = NULL,
  title = NULL,
  subtitle = NULL,
  caption = NULL,
  ncol = NULL,
  nrow = NULL,
  guides = "keep",
  ...
)

Arguments

object

an object, the result of a call to evaluate_smooth().

normalize

logical; normalize the penalty to the range -1, 1?

continuous_fill

suitable scale used for the filled surface. If NULL, the default used is scale_fill_distiller(palette = "RdBu", type = "div").

xlab

character or expression; the label for the x axis. If not supplied, no axis label will be drawn. May be a vector, one per penalty.

ylab

character or expression; the label for the y axis. If not supplied, no axis label will be drawn. May be a vector, one per penalty.

title

character or expression; the title for the plot. See ggplot2::labs(). May be a vector, one per penalty.

subtitle

character or expression; the subtitle for the plot. See ggplot2::labs(). May be a vector, one per penalty.

caption

character or expression; the plot caption. See ggplot2::labs(). May be a vector, one per penalty.

ncol, nrow

numeric; the numbers of rows and columns over which to spread the plots.

guides

character; one of "keep" (the default), "collect", or "auto". Passed to patchwork::plot_layout()

...

arguments passed to other methods.

Examples

load_mgcv()
dat <- data_sim("eg4", n = 400, seed = 42)
m <- gam(y ~ s(x0) + s(x1, bs = 'cr') + s(x2, bs = 'bs', by = fac),
         data = dat, method = "REML")

## produce a multi-panel plot of all penalties
draw(penalty(m))

# for a specific smooth
draw(penalty(m, smooth = "s(x2):fac1"))

gratia

Graceful 'ggplot'-Based Graphics and Other Functions for GAMs Fitted Using 'mgcv'

v0.6.0
MIT + file LICENSE
Authors
Gavin L. Simpson [aut, cre] (<https://orcid.org/0000-0002-9084-8413>), Henrik Singmann [ctb] (<https://orcid.org/0000-0002-4842-3657>)
Initial release
2021-04-17

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.