View source: R/export-ObservationCounts.R
plot_counts_with_mean | R Documentation |
Computes counts of observations for each combination of two variables and displays them as a heatmap, with an overlaid line showing the mean of the second variable across the first. If a stratification variable is provided, observations are counted per strata and strata-specific heatmaps are displayed in individual panels. If an additional stratification variable is provided, separate plot windows are created for each level.
plot_counts_with_mean(
data,
x,
y,
stratify_by = NULL,
for_each = NULL,
title = NULL,
subtitle = NULL,
heatmap_legend = "Count",
mean_legend = "Mean",
viridis_color_option = "D",
mean_color = "coral"
)
data |
Data frame containing all input variables. |
x |
Variable in |
y |
Variable in |
stratify_by |
(Optional) Stratification variable. If
supplied, counts and means are computed for each level 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 |
heatmap_legend |
(Optional) Label for the heatmap legend; defaults to "Count". |
mean_legend |
(Optional) Label for the overlay mean line legend; defaults to "Mean". |
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. |
mean_color |
(Optional) Color for the overlay mean line; defaults to "coral". |
If for_each
is not supplied, a ggplot
object showing a
heatmap of counts with a mean overlay line, optionally faceted by stratify_by
.
If for_each
is supplied, a named list of such plots.
plot_counts_1D
, plot_counts_2D
,
plot_binned_counts
, ggplot
data("toy_data")
# Heatmap of counts by age vs. period with mean age overlay
plot_counts_with_mean(toy_data, x = period, y = age)
# Heatmap of counts by age vs. period with mean age overlay, stratified by education
plot_counts_with_mean(toy_data, x = period, y = age,
stratify_by = education)
# Heatmap of counts by age vs. period with mean age overlay, stratified by education, for each sex
plot_counts_with_mean(toy_data, x = period, y = 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.