Create an Smooth Line Chart
v_smooth.RdCreate an Smooth Line Chart
Usage
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
)Arguments
- vc
A chart initialized with
vchart().- mapping
Default list of aesthetic mappings to use for chart.
- data
Default dataset to use for chart. If not already a
data.frame, it will be coerced to withas.data.frame.- name
Name for the serie, only used for single serie (no
color/fillaesthetic supplied).- method
Smoothing method (function) to use, accepts either
NULLor a character vector, e.g."lm","glm","gam","loess"or a function, e.g.MASS::rlmormgcv::gam,stats::lm, orstats::loess."auto"is also accepted for backwards compatibility. It is equivalent toNULL.For
method = NULLthe 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; otherwisemgcv::gam()is used withformula = y ~ s(x, bs = "cs")withmethod = "REML". Somewhat anecdotally,loessgives 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 thatmethod = NULLwould use, then setmethod = "gam", formula = y ~ s(x, bs = "cs").- formula
Formula to use in smoothing function, eg.
y ~ x,y ~ poly(x, 2),y ~ log(x).NULLby default, in which casemethod = NULLimpliesformula = y ~ xwhen there are fewer than 1,000 observations andformula = y ~ s(x, bs = "cs")otherwise.- se
Display confidence interval around smooth? (
TRUEby default, seelevelto control.)- n
Number of points at which to evaluate smoother.
- span
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 whenmethod = NULL(the default) and there are fewer than 1,000 observations.- ...
Additional parameters for lines.
- args_area
Arguments for area.
- data_id, serie_id
ID for the data/serie, can be used to further customize the chart with
v_specs().
Value
A vchart() htmlwidget object.
Examples
library(vchartr)
data("mpg", package = "ggplot2")
vchart(mpg, aes(displ, hwy)) %>%
v_smooth()
#> `geom_smooth()` using method = 'loess' and formula = 'y ~ x'
vchart(mpg, aes(displ, hwy)) %>%
v_smooth(se = FALSE)
#> `geom_smooth()` using method = 'loess' and formula = 'y ~ x'
vchart(mpg, aes(displ, hwy, color = class)) %>%
v_smooth()
#> `geom_smooth()` using method = 'loess' and formula = 'y ~ x'
#> Warning: span too small. fewer data values than degrees of freedom.
#> Warning: pseudoinverse used at 5.6935
#> Warning: neighborhood radius 0.5065
#> Warning: reciprocal condition number 0
#> Warning: There are other near singularities as well. 0.65044
#> Warning: span too small. fewer data values than degrees of freedom.
#> Warning: pseudoinverse used at 5.6935
#> Warning: neighborhood radius 0.5065
#> Warning: reciprocal condition number 0
#> Warning: There are other near singularities as well. 0.65044
#> Warning: pseudoinverse used at 4.008
#> Warning: neighborhood radius 0.708
#> Warning: reciprocal condition number 0
#> Warning: There are other near singularities as well. 0.25
#> Warning: pseudoinverse used at 4.008
#> Warning: neighborhood radius 0.708
#> Warning: reciprocal condition number 0
#> Warning: There are other near singularities as well. 0.25