Creates an interactive plot using ggiraph. This function extends
gf_smooth() with interactive features like tooltips and clickable elements.
gf_smooth_interactive(
object = NULL,
gformula = NULL,
data = NULL,
...,
method = "auto",
formula = y ~ x,
se = FALSE,
method.args,
n = 80,
span = 0.75,
fullrange = FALSE,
level = 0.95,
xlab,
ylab,
title,
subtitle,
caption,
stat = "smooth",
position = "identity",
show.legend = NA,
show.help = NULL,
inherit = TRUE,
environment = parent.frame()
)A gg object that can be displayed with gf_girafe().
When chaining, this holds an object produced in the earlier portions of the chain. Most users can safely ignore this argument. See details and examples.
A formula with shape y ~ x. Faceting can be
achieved by including | in the formula.
A data frame with the variables to be plotted.
Additional arguments passed to the underlying interactive
geom. This is where ggiraph's interactive aesthetics are supplied,
including tooltip (text shown on hover), data_id
(identifiers used for interactive selection), and onclick
(JavaScript run on click).
Smoothing method (function) to use, accepts either
NULL or a character vector, e.g. "lm", "glm",
"gam", "loess" or a function, e.g. MASS::rlm or
mgcv::gam, stats::lm, or stats::loess.
"auto" is also accepted for backwards compatibility. It is
equivalent to NULL. For method = NULL the smoothing
method is chosen based on the size of the largest group (across all
panels). stats::loess() is used for less
than 1,000 observations; otherwise mgcv::gam()
is used with formula = y ~ s(x, bs = "cs") with method =
"REML". Somewhat anecdotally, loess gives a better appearance,
but is \(O(N^{2})\) in memory, so does not work for larger
datasets. If you have fewer than 1,000 observations but want to use
the same gam() model that method = NULL would use, then
set method = "gam", formula = y ~ s(x, bs = "cs").
Formula to use in smoothing function, eg. y ~ x,
y ~ poly(x, 2), y ~ log(x). NULL by default, in
which case method = NULL implies formula = y ~ x when
there are fewer than 1,000 observations and formula = y ~ s(x,
bs = "cs") otherwise.
Display confidence band around smooth? (TRUE by
default, see level to control.)
List of additional arguments passed on to the
modelling function defined by method.
Number of points at which to evaluate smoother.
Controls the amount of smoothing for the default loess
smoother. Smaller numbers produce wigglier lines, larger numbers
produce smoother lines. Only used with loess, i.e. when method =
"loess", or when method = NULL (the default) and there are
fewer than 1,000 observations.
If TRUE, the smoothing line gets expanded to the
range of the plot, potentially beyond the data. This does not extend
the line into any additional padding created by expansion.
Level of confidence band to use (0.95 by default).
Label for x-axis. See also
gf_labs().
Label for y-axis. See also
gf_labs().
Title, sub-title, and caption for the plot. See also
gf_labs().
Title, sub-title, and caption for the plot. See also
gf_labs().
Title, sub-title, and caption for the plot. See also
gf_labs().
A character string naming the stat used to make the layer.
Either a character string naming the position function used for the layer or a position object returned from a call to a position function.
A logical indicating whether this layer should be
included in the legends. NA, the default, includes layer in the
legends if any of the attributes of the layer are mapped.
If TRUE, display some minimal help.
A logical indicating whether default attributes are inherited.
An environment in which to look for variables not
found in data.
onclick: JavaScript code (as character string) executed when clicking elements.
Additional ggiraph aesthetics may be available depending on the geom.
gf_smooth(), gf_girafe()
# Interactive smooth line with confidence band
mtcars |>
gf_point_interactive(mpg ~ wt, alpha = 0.5) |>
gf_smooth_interactive(tooltip = ~ "loess line with confidence band", se = TRUE, alpha = 0.5) |>
gf_girafe()
Run the code above in your browser using DataLab