View source: R/export-ObservationCounts.R
plot_counts_1D | R Documentation |
Computes the number of observations at each value of a specified variable and creates a line plot of these counts using ggplot2. If a stratification variable is provided, counts are calculated per strata and plotted as separate colored lines. If an additional stratification variable is provided, separate plot windows are created for each level.
plot_counts_1D(
data,
x,
stratify_by = NULL,
for_each = NULL,
title = "Observation counts",
subtitle = NULL,
legend_title = NULL,
x_lab = NULL,
y_lab = NULL,
viridis_color_option = "D"
)
data |
Data frame containing all input variables. |
x |
Variable in |
stratify_by |
(Optional) Stratification variable. If
supplied, counts are computed for each combination of |
for_each |
(Optional) Additional stratification variable. If supplied,
separate plot windows are created per level of |
title |
(Optional) Plot title; defaults to |
subtitle |
(Optional) Plot subtitle; defaults to |
legend_title |
(Optional) Legend title; defaults to name of |
x_lab |
(Optional) Label for the x-axis; defaults to the name of |
y_lab |
(Optional) Label for the y-axis; defaults to the name of |
viridis_color_option |
(Optional) Option for color gradient; defaults to "D". Options are "A", "B", "C", "D", E", "F", "G", "H". See viridis for information, or experiment yourself. |
A ggplot object displaying counts across the variable supplied in x
,
optionally stratified by stratify_by
. If for_each
is supplied, separate plots are created in separate windows for each level.
Visuals can be modified with ggplot2.
plot_counts_2D
, plot_binned_counts
,
plot_counts_with_mean
, ggplot
data("toy_data")
# Counts by age
plot_counts_1D(toy_data, x = age)
# Counts by age, stratified by education level
plot_counts_1D(toy_data, x = age,
stratify_by = education)
# Count by age, stratified by education level, for each sex
plot_counts_1D(toy_data, x = age,
stratify_by = education, for_each = sex)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.