powered by
This function creates a clean, publication-quality box plot for numeric variables, optionally grouped by a categorical variable.
plot_boxplot(data, col, group_col = NULL, add_points = TRUE)
A ggplot object
A data.frame containing survey data
Character string specifying column name for numeric variable
Character string specifying column name for grouping variable (optional)
Logical whether to add individual data points (default: TRUE)
data <- data.frame(age = c(25, 30, 35, 40, 45), gender = c("M", "F", "M", "F", "M")) box_plot <- plot_boxplot(data, "age") grouped_box <- plot_boxplot(data, "age", "gender")
Run the code above in your browser using DataLab