Create an Smooth Line Chart
v_smooth(
vc,
mapping = NULL,
data = NULL,
name = NULL,
method = NULL,
formula = NULL,
se = TRUE,
n = 80,
span = 0.75,
...,
args_area = NULL,
serie_id = NULL,
data_id = NULL
)A vchart()
htmlwidget object.
A chart initialized with vchart().
Default list of aesthetic mappings to use for chart.
Default dataset to use for chart. If not already
a data.frame, it will be coerced to with as.data.frame.
Name for the serie, only used for single serie (no color/fill aesthetic supplied).
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 interval around smooth? (TRUE by default, see
level to control.)
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.
Additional parameters for lines.
Arguments for area.
ID for the data/serie, can be used to further customize the chart with v_specs().
library(vchartr)
data("mpg", package = "ggplot2")
vchart(mpg, aes(displ, hwy)) %>%
v_smooth()
vchart(mpg, aes(displ, hwy)) %>%
v_smooth(se = FALSE)
vchart(mpg, aes(displ, hwy, color = class)) %>%
v_smooth()
Run the code above in your browser using DataLab