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

draw.evaluated_smooth

Plot estimated smooths


Description

Plots estimated univariate and bivariate smooths using ggplot2.

Usage

## S3 method for class 'evaluated_1d_smooth'
draw(
  object,
  rug = NULL,
  ci_level = 0.95,
  constant = NULL,
  fun = NULL,
  xlab,
  ylab,
  title = NULL,
  subtitle = NULL,
  caption = NULL,
  partial_residuals = NULL,
  response_range = NULL,
  ...
)

## S3 method for class 'evaluated_2d_smooth'
draw(
  object,
  show = c("estimate", "se"),
  contour = TRUE,
  contour_col = "black",
  n_contour = NULL,
  constant = NULL,
  fun = NULL,
  xlab,
  ylab,
  title = NULL,
  subtitle = NULL,
  caption = NULL,
  response_range = NULL,
  continuous_fill = NULL,
  ...
)

## S3 method for class 'evaluated_re_smooth'
draw(
  object,
  qq_line = TRUE,
  constant = NULL,
  fun = NULL,
  xlab,
  ylab,
  title = NULL,
  subtitle = NULL,
  caption = NULL,
  response_range = NULL,
  ...
)

## S3 method for class 'evaluated_fs_smooth'
draw(
  object,
  rug = NULL,
  constant = NULL,
  fun = NULL,
  xlab,
  ylab,
  title = NULL,
  subtitle = NULL,
  caption = NULL,
  response_range = NULL,
  discrete_colour = NULL,
  ...
)

## S3 method for class 'evaluated_parametric_term'
draw(
  object,
  ci_level = 0.95,
  constant = NULL,
  fun = NULL,
  xlab,
  ylab,
  title = NULL,
  subtitle = NULL,
  caption = NULL,
  rug = TRUE,
  position = "identity",
  response_range = NULL,
  ...
)

Arguments

object

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

rug

For evaluate_smooth(), a numeric vector of values for the location of data on the x axis. The default of NULL results in no rug plot being drawn. For evaluate_parametric_terms(), a logical to indicate if a rug plot should be drawn.

ci_level

numeric between 0 and 1; the coverage of credible interval.

constant

numeric; a constant to add to the estimated values of the smooth. constant, if supplied, will be added to the estimated value before the confidence band is computed.

fun

function; a function that will be applied to the estimated values and confidence interval before plotting. Can be a function or the name of a function. Function fun will be applied after adding any constant, if provided.

xlab

character or expression; the label for the x axis. If not supplied, a suitable label will be generated from object.

ylab

character or expression; the label for the y axis. If not supplied, a suitable label will be generated from object.

title

character or expression; the title for the plot. See ggplot2::labs().

subtitle

character or expression; the subtitle for the plot. See ggplot2::labs().

caption

character or expression; the plot caption. See ggplot2::labs().

partial_residuals

data frame; partial residuals and data values if partial residuals are drawn. Should have names ..p_resid and ..orig_x if supplied.

response_range

numeric; a vector of two values giving the range of response data for the guide. Used to fix plots to a common scale/range. Ignored if show is set to "se".

...

arguments passed to other methods.

show

character; plot the estimated smooth ("estimate") or its standard error ("se").

contour

logical; should contours be draw on the plot using ggplot2::geom_contour().

contour_col

colour specification for contour lines.

n_contour

numeric; the number of contour bins. Will result in n_contour - 1 contour lines being drawn. See ggplot2::geom_contour().

continuous_fill

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

qq_line

logical; draw a reference line through the lower and upper theoretical quartiles.

discrete_colour

an appropriate discrete colour scale from ggplot2. The scale will need to be able to provide as many colours as there are levels in the factor variable involved in the smooth. Suitable alternatives include ggplot2::scale_colour_viridis_d().

position

Position adjustment, either as a string, or the result of a call to a position adjustment function.

Value

Author(s)

Gavin L. Simpson

Examples

load_mgcv()

dat <- data_sim("eg1", n = 400, dist = "normal", scale = 2, seed = 2)
m1 <- gam(y ~ s(x0) + s(x1) + s(x2) + s(x3), data = dat, method = "REML")

sm <- evaluate_smooth(m1, "s(x2)")
draw(sm)

## supply constant to shift y axis scale
draw(sm, constant = coef(m1)[1])

dat <- data_sim("eg2", n = 1000, dist = "normal", scale = 1, seed = 2)
m2 <- gam(y ~ s(x, z, k = 40), data = dat, method = "REML")

sm <- evaluate_smooth(m2, "s(x,z)", n = 100)
draw(sm)

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.