View source: R/export-ObservationCounts.R
plot_mean_response_1D | R Documentation |
Computes the mean of a specified response variable at each value of a specified x variable and displays a line plot using ggplot2. If a stratification variable is provided, means 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_mean_response_1D(
data,
response,
x,
stratify_by = NULL,
for_each = NULL,
title = NULL,
subtitle = NULL,
legend_title = NULL,
x_lab = NULL,
y_lab = NULL,
viridis_color_option = "D"
)
data |
A |
response |
A numeric variable in |
x |
A 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 the mean of the response 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_mean_response_2D
, ggplot
data("toy_data")
# Mean by age
plot_mean_response_1D(toy_data, response = count, x = age)
# Mean count by age, stratified by education
plot_mean_response_1D(toy_data, response = count, x = age,
stratify_by = education)
# Mean count by age, stratified by education, for each sex
plot_mean_response_1D(toy_data, response = count, 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.