| plot_density | R Documentation |
Create a density plot for one or more numeric variables using kernel density estimation.
plot_density(
data,
x,
facet_var = NULL,
facet_scale = "free",
facet_nrow = NULL,
facet_ncol = NULL,
color = NULL,
fill = NULL,
title = NULL,
subtitle = NULL,
xlab = NULL,
ylab = NULL,
caption = NULL,
line_width = 0.1,
line_type = "solid",
line_color = "grey35",
fill_color = "grey35",
fill_alpha = 0.5,
theme_set = theme_tscv(),
theme_config = list(),
...
)
data |
A |
x |
Unquoted column in |
facet_var |
Optional unquoted column in |
facet_scale |
Character value defining facet axis scaling. Common values
are |
facet_nrow |
Optional integer. Number of rows in the facet layout. |
facet_ncol |
Optional integer. Number of columns in the facet layout. |
color |
Optional unquoted column in |
fill |
Optional unquoted column in |
title |
Character value. Plot title. |
subtitle |
Character value. Plot subtitle. |
xlab |
Character value. Label for the x-axis. |
ylab |
Character value. Label for the y-axis. |
caption |
Character value. Plot caption. |
line_width |
Numeric value defining the density line width. |
line_type |
Character or numeric value defining the density line type. |
line_color |
Character value defining the density line color. Ignored
when |
fill_color |
Character value defining the fill color under the density
curve. Ignored when |
fill_alpha |
Numeric value between |
theme_set |
A complete |
theme_config |
A named |
... |
Further arguments passed to |
plot_density() is a convenience wrapper around
ggplot2::geom_density(). It is useful for comparing the distribution
of values across one or more time series, models, groups, or residual sets.
The arguments x, facet_var, color, and fill are
passed as unquoted column names.
If color is supplied, both line color and fill color are mapped to that
variable. In this case, line_color and fill_color are ignored.
If color is not supplied, all density curves use line_color and
fill_color.
Missing values are removed before plotting.
Additional arguments can be passed to ggplot2::geom_density() through
..., for example adjust, bw, or kernel.
Additional theme settings can be supplied through theme_config. This
should be a named list of arguments passed to ggplot2::theme().
An object of class ggplot.
Other data visualization:
plot_bar(),
plot_histogram(),
plot_line(),
plot_point(),
plot_qq(),
scale_color_tscv(),
scale_fill_tscv(),
theme_tscv(),
tscv_cols(),
tscv_pal()
library(dplyr)
data <- M4_monthly_data |>
filter(series %in% c("M23100", "M14395"))
plot_density(
data = data,
x = value,
facet_var = series,
title = "Distribution of M4 Monthly Values",
subtitle = "Kernel density estimates by series",
xlab = "Value",
ylab = "Density"
)
plot_density(
data = data,
x = value,
color = series,
title = "Distribution of M4 Monthly Values",
subtitle = "Kernel density estimates by series",
xlab = "Value",
ylab = "Density",
adjust = 1.2
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.