| Title: | Tools and helpful wrappers for analysts at Stem (https://www.stem.cz) |
|---|---|
| Description: | Color palettes, ploting functions and more for working at Stem. |
| Authors: | Aleš Vomáčka [aut, cre] (ORCID: <https://orcid.org/0000-0002-1605-8026>) |
| Maintainer: | Aleš Vomáčka <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.2.2 |
| Built: | 2026-11-10 23:35:06 UTC |
| Source: | https://github.com/stem-cz/stemtools |
This function is a wrapper around forcats::fct_collapse().
It takes a dataframe, a factor variable, and a list of factor levels to collapse.
collapse_cats(data, item, collapse_cats)collapse_cats(data, item, collapse_cats)
data |
dataset |
item |
factor variable |
collapse_cats |
list of factor levels to collapse in shape of |
new data frame with collapsed factor levels
collapse_cats(trust, police, list(Agree = c("Definitely Agree", "Rather Agree")))collapse_cats(trust, police, list(Agree = c("Definitely Agree", "Rather Agree")))
Creates a standard Stem project directory structure, a minimal README.md
and, optionally, a .gitignore file. This function backs the RStudio
"New Project" template defined in
inst/rstudio/templates/project/create_project.dcf, but can also be called
directly.
create_project(path, createGitignore = TRUE, ...)create_project(path, createGitignore = TRUE, ...)
path |
Path to the project directory to create. |
createGitignore |
If |
... |
Additional named arguments collected from the RStudio template wizard. Currently ignored. |
Invisibly returns path. Called for its side effect of creating the
project directory structure on disk.
## Not run: create_project(file.path(tempdir(), "my-analysis")) ## End(Not run)## Not run: create_project(file.path(tempdir(), "my-analysis")) ## End(Not run)
Discrete ggplot2 scales that apply a stem colour palette to the colour or fill aesthetic.
Three aliases are provided:
scale_colour_stem() — maps to the colour aesthetic (British spelling).
scale_color_stem() — alias for scale_colour_stem() (American spelling).
scale_fill_stem() — maps to the fill aesthetic.
All functions delegate to ggplot2::discrete_scale() via stem_palette_gen(), so any argument
accepted by discrete_scale() (e.g. name, breaks, labels, na.value, drop) can
be passed through ....
scale_fill_stem(palette = "div1", direction = 1, ...) scale_colour_stem(palette = "div1", direction = 1, ...) scale_color_stem(palette = "div1", direction = 1, ...)scale_fill_stem(palette = "div1", direction = 1, ...) scale_colour_stem(palette = "div1", direction = 1, ...) scale_color_stem(palette = "div1", direction = 1, ...)
palette |
Name of the palette. See |
direction |
|
... |
Additional arguments passed to |
A ggplot2 Scale object to be added to a plot with +.
stem_palette(), stem_palette_gen(), ggplot2::discrete_scale()
ggplot2::ggplot(data = mtcars, mapping = ggplot2::aes(x = mpg, y = hp, color = as.factor(am))) + ggplot2::geom_point() + scale_colour_stem()ggplot2::ggplot(data = mtcars, mapping = ggplot2::aes(x = mpg, y = hp, color = as.factor(am))) + ggplot2::geom_point() + scale_colour_stem()
Computes SE for the mean using the old-school formula.
se_mean(x)se_mean(x)
x |
numeric vector |
numeric value representing SE for means
se_mean(trust$age)se_mean(trust$age)
Computes SE for the median using the old-school formula.
This assumes normal distribution.
se_median(x)se_median(x)
x |
numeric vector |
numeric value representing SE for medians
se_median(trust$age)se_median(trust$age)
Computes SE for proportions using the old-school formula.
se_prop(p, n)se_prop(p, n)
p |
proportion |
n |
sample size |
numeric value representing SE for proportions
p = 0.3 n = 200 se_prop(p = p, n = n)p = 0.3 n = 200 se_prop(p = p, n = n)
Selects n colours from a diverging palette while preserving its symmetric, center-anchored
structure. Rather than simply taking the first n colours, this function samples
symmetrically from both ends of the palette:
Odd n: the palette midpoint is always included, with an equal number of colours
drawn from each side.
Even n: colours are drawn evenly from the left and right halves.
The selected colours are always returned in their original palette order.
select_diverging(palette, n)select_diverging(palette, n)
palette |
Character vector of hex colour codes representing the full diverging palette. |
n |
Number of colours to select. Must be between 1 and |
Character vector of n hex colour codes in original palette order.
stem_palette_gen(), stem_palette()
pal <- stem_palette("modern") # Odd n: midpoint included, balanced sides select_diverging(pal, n = 3) # Even n: two from each end select_diverging(pal, n = 4)pal <- stem_palette("modern") # Odd n: midpoint included, balanced sides select_diverging(pal, n = 3) # Even n: two from each end select_diverging(pal, n = 4)
Converts plot with stem_as_mschart() and adds it to an existing officer
document. For a PowerPoint document the chart is placed on the current
slide, so add a slide with officer::add_slide() first.
stem_add_chart( x, plot, width = NULL, height = NULL, left = NULL, top = NULL, units = "cm", location = NULL, ... )stem_add_chart( x, plot, width = NULL, height = NULL, left = NULL, top = NULL, units = "cm", location = NULL, ... )
x |
An |
plot |
A ggplot2 object created by a Stem plotting function, or an
|
width, height
|
Size of the chart, in |
left, top
|
PowerPoint only: position of the chart's top-left corner, in
|
units |
Unit of |
location |
PowerPoint only: an |
... |
Passed to |
The document x, updated.
## Not run: doc <- officer::read_pptx() doc <- officer::add_slide(doc, "Title and Content", "Office Theme") doc <- stem_add_chart(doc, stem_barplot(trust, government)) print(doc, target = "chart.pptx") ## End(Not run)## Not run: doc <- officer::read_pptx() doc <- officer::add_slide(doc, "Title and Content", "Office Theme") doc <- stem_add_chart(doc, stem_barplot(trust, government)) print(doc, target = "chart.pptx") ## End(Not run)
Takes a ggplot2 object created by one of the Stem plotting functions and
returns an mschart::ms_barchart() that renders as closely as possible to
the ggplot original, but is a native Office chart: once placed in a
PowerPoint or Word file it carries its own embedded worksheet, so the source
data can be opened and edited in Excel.
stem_as_mschart( plot, title = NULL, labels = NULL, legend = NULL, num_fmt = NULL, axis_num_fmt = "0\"%\"", axis_show = TRUE, axis_major_unit = NULL, gap_width = 30, value_name = "%" )stem_as_mschart( plot, title = NULL, labels = NULL, legend = NULL, num_fmt = NULL, axis_num_fmt = "0\"%\"", axis_show = TRUE, axis_major_unit = NULL, gap_width = 30, value_name = "%" )
plot |
A ggplot2 object created by |
title |
Chart title. Defaults to the ggplot title (set with
|
labels |
If |
legend |
If |
num_fmt |
Excel number format code for the data labels, e.g. |
axis_num_fmt |
Excel number format code for the value axis. Defaults to
|
axis_show |
If |
axis_major_unit |
Spacing of the value axis ticks, in percentage
points. Defaults to |
gap_width |
Gap between bars, as a percentage of the bar width. |
value_name |
Name of the value column in the embedded worksheet; it is also the series name of charts without a fill variable. |
The aggregated data, the category order, the palette, the label formatting and the fonts are all read back off the ggplot object, so the native chart needs no recomputation and stays in sync with the ggplot version.
A few ggplot features have no Office equivalent and are dropped, with a
message: confidence interval error bars (errorbar = TRUE) and the
background bars of stem_multiselect().
An object of class ms_barchart, ready for
officer::ph_with() / mschart::body_add_chart() or for the Stem helpers
stem_add_chart(), stem_export_pptx() and stem_export_docx().
stem_add_chart(), stem_export_pptx(), stem_export_docx()
## Not run: chart <- stem_as_mschart(stem_barplot(trust, government)) stem_export_pptx( stem_barplot(trust, government), stem_battery(trust, items = c(police, eu, government, army)), path = "charts.pptx" ) ## End(Not run)## Not run: chart <- stem_as_mschart(stem_barplot(trust, government)) stem_export_pptx( stem_barplot(trust, government), stem_battery(trust, items = c(police, eu, government, army)), path = "charts.pptx" ) ## End(Not run)
Plots the (possibly weighted) distribution of a categorical variable as
horizontal bars. Without a group, one bar is drawn per item category.
Supplying a group variable instead draws one stacked horizontal bar per
group category, with the item mapped to fill; proportions are then computed
within each group, so every bar sums to 100%.
stem_barplot( data, item, group = NULL, weight = NULL, collapse_item = NULL, collapse_group = NULL, palette = "div1", direction = 1, labels = TRUE, label_accuracy = 1, label_suffix = "", label_hide = NULL, label_color = "black", label_bicolor = TRUE, errorbar = FALSE, title_show = FALSE, title_quote = FALSE, title_wrap = 80 )stem_barplot( data, item, group = NULL, weight = NULL, collapse_item = NULL, collapse_group = NULL, palette = "div1", direction = 1, labels = TRUE, label_accuracy = 1, label_suffix = "", label_hide = NULL, label_color = "black", label_bicolor = TRUE, errorbar = FALSE, title_show = FALSE, title_quote = FALSE, title_wrap = 80 )
data |
Data frame holding the item (and group) variables. |
item |
Categorical variable to plot. |
group |
Optional grouping variable. When supplied, one stacked horizontal bar is drawn per group category (with the item mapped to fill) and proportions are computed within each group. |
weight |
Optional survey weights. |
collapse_item |
Optional named list passed to |
collapse_group |
Optional named list to collapse (or rename) group categories. |
palette |
Name of a Stem palette. See |
direction |
Palette direction. Use |
labels |
If |
label_accuracy |
Rounding accuracy of labels. |
label_suffix |
Suffix appended to labels. Defaults to |
label_hide |
Proportions below this threshold are left unlabelled.
Defaults to |
label_color |
Colour of the segment labels in grouped (stacked) plots.
Defaults to |
label_bicolor |
If |
errorbar |
If |
title_show |
If |
title_quote |
If |
title_wrap |
Maximum number of characters per title line; longer titles
are wrapped onto several lines so they do not overflow the plot. Use |
A ggplot2 object.
## Not run: stem_barplot(trust, government) stem_barplot(trust, police, group = eu_index, weight = W) ## End(Not run)## Not run: stem_barplot(trust, government) stem_barplot(trust, police, group = eu_index, weight = W) ## End(Not run)
Plots a set of categorical variables that share the same response categories
(e.g. a battery of Likert items) as a single chart, drawing one stacked
horizontal bar per item. Internally the items are reshaped to long format and
handed to the same machinery as stem_barplot(), with the item taking the
role of the group.
stem_battery( data, items, weight = NULL, order_by = NULL, item_label = TRUE, palette = "div1", direction = 1, labels = TRUE, label_accuracy = 1, label_suffix = "", label_hide = 0.05, label_color = "black", label_bicolor = TRUE )stem_battery( data, items, weight = NULL, order_by = NULL, item_label = TRUE, palette = "div1", direction = 1, labels = TRUE, label_accuracy = 1, label_suffix = "", label_hide = 0.05, label_color = "black", label_bicolor = TRUE )
data |
Data frame holding the item (and group) variables. |
items |
Items to plot. Supports tidyselect helpers (e.g.
|
weight |
Optional survey weights. |
order_by |
Optional vector of response categories used to order the
items, e.g. |
item_label |
If |
palette |
Name of a Stem palette. See |
direction |
Palette direction. Use |
labels |
If |
label_accuracy |
Rounding accuracy of labels. |
label_suffix |
Suffix appended to labels. Defaults to |
label_hide |
Proportions below this threshold are left unlabelled.
Defaults to |
label_color |
Colour of the segment labels in grouped (stacked) plots.
Defaults to |
label_bicolor |
If |
A ggplot2 object.
## Not run: stem_battery(trust, items = c(police, eu, government, army)) stem_battery(trust, items = c(police, eu, government, army), weight = W, order_by = c("Definitely Agree", "Rather Agree")) ## End(Not run)## Not run: stem_battery(trust, items = c(police, eu, government, army)) stem_battery(trust, items = c(police, eu, government, army), weight = W, order_by = c("Definitely Agree", "Rather Agree")) ## End(Not run)
Writes a .docx file holding one native Office chart per plot, each with an
embedded worksheet that can be edited in Excel.
stem_export_docx( ..., path, template = NULL, width = 15, height = 10, units = "cm", chart_args = list() )stem_export_docx( ..., path, template = NULL, width = 15, height = 10, units = "cm", chart_args = list() )
... |
One or more ggplot2 objects created by the Stem plotting
functions (or |
path |
Path of the |
template |
Optional path to a |
width, height
|
Size of each chart, in |
units |
Unit of |
chart_args |
A named list of arguments passed on to
|
The path, invisibly.
stem_as_mschart(), stem_export_pptx()
## Not run: stem_export_docx(stem_barplot(trust, government), path = "trust.docx") # Half-page charts. stem_export_docx( stem_barplot(trust, government), path = "trust.docx", width = 16, height = 8 ) ## End(Not run)## Not run: stem_export_docx(stem_barplot(trust, government), path = "trust.docx") # Half-page charts. stem_export_docx( stem_barplot(trust, government), path = "trust.docx", width = 16, height = 8 ) ## End(Not run)
Writes one slide per plot, each holding a native Office chart whose source data can be edited in Excel.
stem_export_pptx( ..., path, template = NULL, layout = "Title and Content", master = "Office Theme", width = NULL, height = NULL, left = NULL, top = NULL, units = "cm", location = NULL, chart_args = list() )stem_export_pptx( ..., path, template = NULL, layout = "Title and Content", master = "Office Theme", width = NULL, height = NULL, left = NULL, top = NULL, units = "cm", location = NULL, chart_args = list() )
... |
One or more ggplot2 objects created by the Stem plotting
functions (or |
path |
Path of the |
template |
Optional path to a |
layout, master
|
Name of the slide layout and of the master to use for the new slides. |
width, height
|
Size of each chart, in |
left, top
|
Position of each chart's top-left corner, in |
units |
Unit of |
location |
An |
chart_args |
A named list of arguments passed on to
|
The path, invisibly.
stem_as_mschart(), stem_export_docx()
## Not run: stem_export_pptx( stem_barplot(trust, government, title_show = TRUE), stem_inline(trust, police), path = "trust.pptx" ) # A 24 x 12 cm chart, 2 cm from the left and 4 cm from the top of the slide. stem_export_pptx( stem_barplot(trust, government), path = "trust.pptx", width = 24, height = 12, left = 2, top = 4 ) ## End(Not run)## Not run: stem_export_pptx( stem_barplot(trust, government, title_show = TRUE), stem_inline(trust, police), path = "trust.pptx" ) # A 24 x 12 cm chart, 2 cm from the left and 4 cm from the top of the slide. stem_export_pptx( stem_barplot(trust, government), path = "trust.pptx", width = 24, height = 12, left = 2, top = 4 ) ## End(Not run)
Plots the (possibly weighted) distribution of a single categorical variable as one stacked horizontal bar. Useful as a compact, inline summary of a single item.
stem_inline( data, item, weight = NULL, collapse_item = NULL, palette = "div1", direction = 1, labels = TRUE, label_accuracy = 1, label_suffix = "", label_hide = 0.05, label_color = "black", label_bicolor = TRUE, title_show = FALSE, title_quote = FALSE, title_wrap = 80 )stem_inline( data, item, weight = NULL, collapse_item = NULL, palette = "div1", direction = 1, labels = TRUE, label_accuracy = 1, label_suffix = "", label_hide = 0.05, label_color = "black", label_bicolor = TRUE, title_show = FALSE, title_quote = FALSE, title_wrap = 80 )
data |
Data frame holding the item (and group) variables. |
item |
Categorical variable to plot. |
weight |
Optional survey weights. |
collapse_item |
Optional named list passed to |
palette |
Name of a Stem palette. See |
direction |
Palette direction. Use |
labels |
If |
label_accuracy |
Rounding accuracy of labels. |
label_suffix |
Suffix appended to labels. Defaults to |
label_hide |
Proportions below this threshold are left unlabelled.
Defaults to |
label_color |
Colour of the segment labels in grouped (stacked) plots.
Defaults to |
label_bicolor |
If |
title_show |
If |
title_quote |
If |
title_wrap |
Maximum number of characters per title line; longer titles
are wrapped onto several lines so they do not overflow the plot. Use |
A ggplot2 object.
## Not run: stem_inline(trust, police) stem_inline(trust, police, weight = W) ## End(Not run)## Not run: stem_inline(trust, police) stem_inline(trust, police, weight = W) ## End(Not run)
Plots a set of "select all that apply" items, showing the share of respondents that picked each option. The items are reshaped to long format and their (possibly weighted) frequencies are rescaled by the number of items so that the bars express percentages of respondents rather than of responses.
stem_multiselect( data, items, group = NULL, weight = NULL, palette = "div1", direction = 1, labels = TRUE, label_accuracy = 1, label_suffix = "", label_hide = 0, infreq_order = TRUE, background = TRUE, background_fill = "grey85", background_alpha = 1 )stem_multiselect( data, items, group = NULL, weight = NULL, palette = "div1", direction = 1, labels = TRUE, label_accuracy = 1, label_suffix = "", label_hide = 0, infreq_order = TRUE, background = TRUE, background_fill = "grey85", background_alpha = 1 )
data |
Data frame holding the item (and group) variables. |
items |
Items to plot. Supports tidyselect helpers (e.g.
|
group |
Optional grouping variable. When supplied, one stacked horizontal bar is drawn per group category (with the item mapped to fill) and proportions are computed within each group. |
weight |
Optional survey weights. |
palette |
Name of a Stem palette. See |
direction |
Palette direction. Use |
labels |
If |
label_accuracy |
Rounding accuracy of labels. |
label_suffix |
Suffix appended to labels. Defaults to |
label_hide |
Proportions below this threshold are left unlabelled.
Defaults to |
infreq_order |
If |
background |
If |
background_fill |
Fill colour of the background bars. |
background_alpha |
Opacity of the background bars. |
A ggplot2 object.
## Not run: stem_multiselect(trust, items = dplyr::starts_with("biggest_concern")) stem_multiselect(trust, items = dplyr::starts_with("biggest_concern"), weight = W) ## End(Not run)## Not run: stem_multiselect(trust, items = dplyr::starts_with("biggest_concern")) stem_multiselect(trust, items = dplyr::starts_with("biggest_concern"), weight = W) ## End(Not run)
Returns a character vector of hex colour codes for the requested palette. The vector carries
a type attribute ("nominal", "diverging", or "sequential") used internally by
stem_palette_gen().
stem_palette(palette = "div1")stem_palette(palette = "div1")
palette |
Name of the palette. One of: Nominal (categorical, unordered data): Sequential (ordered data from low to high): Diverging (data with a meaningful midpoint): |
Character vector of hex colour codes with a type attribute
("nominal", "diverging", or "sequential").
stem_palette_gen(), scale_colour_stem(), scale_fill_stem()
# Returns a plain character vector stem_palette("modern") # Inspect the palette type attr(stem_palette("modern"), "type") # Use with scales package for inspection scales::show_col(stem_palette("nom1"))# Returns a plain character vector stem_palette("modern") # Inspect the palette type attr(stem_palette("modern"), "type") # Use with scales package for inspection scales::show_col(stem_palette("nom1"))
Returns a function function(n) that selects n colours from the named palette.
This factory is used internally by scale_colour_stem() and scale_fill_stem() to
satisfy ggplot2's discrete scale interface, but can also be called directly.
Diverging palettes use select_diverging() to pick colours that preserve the
symmetric structure of the palette. All other palette types return the first n colours,
optionally reversed.
stem_palette_gen(palette = "div1", direction = 1)stem_palette_gen(palette = "div1", direction = 1)
palette |
Name of the palette. See |
direction |
|
A function(n) that returns a character vector of n hex colour codes.
stem_palette(), select_diverging(), scale_colour_stem()
# Create a generator then call it for 3 colours gen <- stem_palette_gen("modern") gen(3) # Reversed order stem_palette_gen("div1", direction = -1)(5)# Create a generator then call it for 3 colours gen <- stem_palette_gen("modern") gen(3) # Reversed order stem_palette_gen("div1", direction = -1)(5)
Plots a visual overview of all available stem colour palettes, grouped by type
(nominal, diverging, sequential). Each row shows one palette's colours as tiles,
similar to RColorBrewer::display.brewer.all().
stem_palettes_all()stem_palettes_all()
A ggplot2 object.
stem_palette(), scale_colour_stem()
stem_palettes_all()stem_palettes_all()
Summarise either numeric or categerical variable, possible segment by another categorical variable.
Actually a wrapper for stem_summarise_cat() and stem_summarise_num().
stem_summarise( data, item, group = NULL, weight = NULL, long = FALSE, collapse_item = NULL, collapse_group = NULL, na.rm = TRUE, return_n = FALSE )stem_summarise( data, item, group = NULL, weight = NULL, long = FALSE, collapse_item = NULL, collapse_group = NULL, na.rm = TRUE, return_n = FALSE )
data |
Dataframe including variables to be analyzed |
item |
Variable to be summarised |
group |
Optional segmenting variable |
weight |
Optional survey weights |
long |
Returns data in long format. Useful if multiple dataframes are to be merged |
collapse_item |
Named list. Optionally collapes (or renames) categories of the item variable (Only if item is categorical). |
collapse_group |
Named list. Optionally collapes (or renames) categories of the group variable |
na.rm |
If |
return_n |
If |
Apart from either point estimates (proportions or means), the function also returns 95% confidence interval bounds.
If unweighted, the intervals are computed using the basic sqrt((p * (1-p)) / n) formula, where n is the size of the
(possibly segmented) sample. If the estimated proportions are very high/low, this may lead to interval estimates outside
of the (0;1) bounds. If weights are used, the confidence intervals come from srvyr/survey (Taylor-series linearization).
If long = TRUE, new column is added holding name of the item (and group) variable. This is useful if you need to loop through
multiple variables and bind the results into a single data frame. See online vignettes for details.
collapse_item and collapse_group can be used to collapse categories of item and group variable. The named list should include
vector of old category names with corresponding to the new category name, e.g. list(Agree = c("Definitely Agree", "Rather Agree").
You can also use the arguments to rename categories (list(Yes = "Agree")) or pass other arguments from the forcats::fct_collapse() function.
If return_n = TRUE, columns holding the absolute frequencies will be added. Column n is the number of observations for the specific combination of
item and grouping variable, item_n is the frequency of the item categories and group_n is the frequency of the group categories.
An aggregated data frame with point estimates (either proportions or means) and 95% confidence intervals.
stem_summarise(data = trust, item = government) stem_summarise(data = trust, item = age, group = eu_index) stem_summarise(data = trust, item = government, collapse_item = list(Agree = c("Definitely Agree", "Rather Agree")))stem_summarise(data = trust, item = government) stem_summarise(data = trust, item = age, group = eu_index) stem_summarise(data = trust, item = government, collapse_item = list(Agree = c("Definitely Agree", "Rather Agree")))
Takes one categorical variable and returns a tidy dataframe, including relative frequencies and absolute size of each group. The variable can be further segmented by another categorical variable. Can also take survey weights. Returns 95% confidence intervals.
stem_summarise_cat( data, item, group = NULL, weight = NULL, long = FALSE, collapse_item = NULL, collapse_group = NULL, na.rm = TRUE, return_n = FALSE )stem_summarise_cat( data, item, group = NULL, weight = NULL, long = FALSE, collapse_item = NULL, collapse_group = NULL, na.rm = TRUE, return_n = FALSE )
data |
Dataframe including variables to be analyzed |
item |
Variable to be summarised |
group |
Optional segmenting variable |
weight |
Optional survey weights |
long |
Returns data in long format. Useful if multiple dataframes are to be merged |
collapse_item |
Named list. Optionally collapes (or renames) categories of the item variable |
collapse_group |
Named list. Optionally collapes (or renames) categories of the group variable |
na.rm |
If |
return_n |
If |
Tidy dataframe
trust |> stem_summarise_cat(item = police, group = eu, weight = W, collapse_item = list(Agree = c("Definitely Agree", "Rather Agree")))trust |> stem_summarise_cat(item = police, group = eu, weight = W, collapse_item = list(Agree = c("Definitely Agree", "Rather Agree")))
Takes one numeric variable and returns a tidy dataframe, including relative mean and absolute size of each group. The variable can be further segmented by another categorical variable. Can also take survey weights. Returns 95% confidence intervals.
stem_summarise_num( data, item, group = NULL, weight = NULL, long = FALSE, collapse_group = NULL, na.rm = TRUE, return_n = FALSE )stem_summarise_num( data, item, group = NULL, weight = NULL, long = FALSE, collapse_group = NULL, na.rm = TRUE, return_n = FALSE )
data |
Dataframe including data to be analyzed |
item |
Variable to be summarised |
group |
Optional segmenting variable |
weight |
Optional survey weights |
long |
Returns data in long format. Useful if multiple dataframes are to be merged |
collapse_group |
Named list. Optionally collapses (or renames) categories of the group variable |
na.rm |
If |
return_n |
If |
Tidy dataframe
trust |> stem_summarise_num(age, group = eu_index, weight = W, collapse_group = list(`Neutral or no opinion` = c("Neutral", "Doesn't Know")))trust |> stem_summarise_num(age, group = eu_index, weight = W, collapse_group = list(`Neutral or no opinion` = c("Neutral", "Doesn't Know")))
A complete ggplot2 theme carrying the Stem look. Because it is complete,
the Stem plotting functions do not apply it themselves; instead activate it
globally with ggplot2::theme_set() so every plot picks it up:
theme_stem( ink = "black", paper = "white", accent = "#35978F", family = "Calibri", label_size = 14, ... )theme_stem( ink = "black", paper = "white", accent = "#35978F", family = "Calibri", label_size = 14, ... )
ink |
Foreground colour used for text, titles and axis lines. Also
passed to |
paper |
Background colour used behind the panel, plot, strips and
legend keys. Also passed to |
accent |
Accent colour passed to |
family |
Font family for all text. Defaults to |
label_size |
Point size of the numeric labels drawn inside the plot
(the |
... |
Arguments to be passed to |
ggplot2::theme_set(theme_stem())
It can still be added to an individual plot with + theme_stem() in the
usual way. The theme is built on ggplot2::theme_grey() with the Stem
overrides layered on top.
A complete ggplot2 ggplot2::theme() object.
## Not run: # Activate globally for the whole session. ggplot2::theme_set(theme_stem()) stem_barplot(trust, government) # Or add it to a single plot. stem_barplot(trust, government) + theme_stem() ## End(Not run)## Not run: # Activate globally for the whole session. ggplot2::theme_set(theme_stem()) stem_barplot(trust, government) # Or add it to a single plot. stem_barplot(trust, government) + theme_stem() ## End(Not run)
Simulated data to use for examples and function testing.
trusttrust
trustA data frame with 1 000 rows and 12 columns:
Generally speaking, can the following be trusted: Police
Generally speaking, can the following be trusted: Czech government
Generally speaking, can the following be trusted: European Union
Generally speaking, can the following be trusted: Army
Generally speaking, can the following be trusted: Scientists
Attitudes towards EU index
Openness towards society index
Age
Sampling weight
Biggest concern about society in the last month
Second biggest concern about society in the last month
Third biggest concern about society in the last month
...