View source: R/export-ObservationCounts.R
plot_mean_response_2D | R Documentation |
Computes the mean of a specified response variable for each combination of two variables and displays it as a heatmap using ggplot2. If a stratification variable is provided, means are calculated 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_mean_response_2D(
data,
response,
x,
y,
stratify_by = NULL,
for_each = NULL,
color_gradient = c("blue", "beige", "red"),
title = NULL,
subtitle = NULL,
x_lab = NULL,
y_lab = NULL
)
data |
Data frame containing all input variables. |
response |
Numeric variable in |
x |
Variable in |
y |
Variable in |
stratify_by |
(Optional) Stratification variable. If
supplied, means are computed for each combination of |
for_each |
(Optional) Additional stratification variable.
If supplied, separate plot windows are created per level of |
color_gradient |
(Optional) Color gradient for the heatmap. Specified as a character vector of three colors, representing: c(<low_counts>, <middle_counts>, <high_counts>).
Defaults to |
title |
Plot title; defaults to |
subtitle |
(Optional) Plot subtitle; defaults to |
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 |
A ggplot object showing the mean of response
across x
and y
, optionally faceted by facet_row
and/or facet_col
.
plot_mean_response_1D
, ggplot
data("toy_data")
# Mean count by age and period
plot_mean_response_2D(toy_data, response = count, x = period, y = age)
# Mean count by age and period, stratified by education level
plot_mean_response_2D(toy_data, response = count, x = period, y = age,
stratify_by = education)
# Mean count by age and period, stratified by education level, for each sex
plot_mean_response_2D(toy_data, response = count, 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.