Learn R Programming

SurveyStat (version 1.0.3)

plot_weighted_bar: Create weighted bar plot for categorical variables

Description

This function creates a bar plot for categorical variables, optionally using survey weights to show weighted frequencies.

Usage

plot_weighted_bar(data, col, weight_col = NULL, show_percentages = TRUE)

Value

A ggplot object

Arguments

data

A data.frame containing survey data

col

Character string specifying column name for categorical variable

weight_col

Character string specifying column name containing weights (optional)

show_percentages

Logical whether to show percentage labels (default: TRUE)

Examples

Run this code
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