powered by
This function creates a bar plot for categorical variables, optionally using survey weights to show weighted frequencies.
plot_weighted_bar(data, col, weight_col = NULL, show_percentages = TRUE)
A ggplot object
A data.frame containing survey data
Character string specifying column name for categorical variable
Character string specifying column name containing weights (optional)
Logical whether to show percentage labels (default: TRUE)
data <- data.frame(gender = c("M", "F", "M", "F"), weight = c(1, 1.2, 0.8, 1.1)) bar_plot <- plot_weighted_bar(data, "gender") weighted_bar <- plot_weighted_bar(data, "gender", "weight")
Run the code above in your browser using DataLab