Learn R Programming

daltoolbox (version 1.2.747)

plot_stackedbar: Plot stacked bar

Description

Stacked bar chart for multiple series per category.

Usage

plot_stackedbar(data, label_x = "", label_y = "", colors = NULL, alpha = 1)

Value

returns a ggplot2::ggplot graphic

Arguments

data

data.frame with category in first column and series in remaining columns

label_x

x‑axis label

label_y

y‑axis label

colors

optional vector of fill colors, one per series

alpha

bar transparency (0–1)

Details

Expects a data.frame with category in the first column and series in remaining columns. Bars are stacked within each category. Provide colors (one per series) to control fills.

Examples

Run this code
#summarizing iris dataset
data <- iris |> dplyr::group_by(Species) |>
dplyr::summarize(Sepal.Length=mean(Sepal.Length), Sepal.Width=mean(Sepal.Width))

#plotting data
grf <- plot_stackedbar(data, colors=c("blue", "red"))
plot(grf)

Run the code above in your browser using DataLab