Plot Distribution of a Categorical Variable as a Stacked Bar
Source:R/plot_1_categorical_var.R
plot_1_categorical_var.RdCreate a single 100% stacked bar displaying the distribution of a categorical variable.
Usage
plot_1_categorical_var(
data,
var,
text_inside_bars = c("count_and_percent", "none", "count", "percent"),
fill_palette = NULL,
bar_width = 0.8,
border_color = "white",
text_size = 4
)Arguments
- data
A data.frame.
- var
A categorical variable in
data.- text_inside_bars
Character specifying labels displayed within bar segments. One of
"count_and_percent","count","percent", or"none".- fill_palette
Optional named vector of fill colors passed to
ggplot2::scale_fill_manual().- bar_width
Width of the stacked bar.
- border_color
Color of borders separating bar segments.
- text_size
Size of text labels displayed within bar segments.
