plot_binary
visualises binary survey responses for specified variables using bar plots.
It leverages the grid_vars
function to create a comparative visual representation,
supporting optional grouping and weighting.
Usage
plot_binary(
data,
vars,
value,
group = NULL,
weight = NULL,
title = NULL,
subtitle = NULL,
totalColour = colour_pal("French Grey"),
groupColours = colour_pal("catExtended")
)
Arguments
- data
A data frame containing survey data.
- vars
A list mapping original column names to new variable names for visualisation. For example,
list(Q1a = "Art", Q1b = "Automobiles")
. This parameter is required.- value
The binary response value (e.g., "Yes") to be visualized. Required.
- group
An optional variable for comparing responses between different groups.
- weight
An optional variable containing weight factors for analysis.
- title
The title of the plot.
- subtitle
The subtitle of the plot.
- totalColour
The colour used for plotting total response percentages (default: French Grey).
- groupColours
A vector of colours used for plotting grouped response percentages (default: an extended categorical palette).
Value
A ggplot2 bar plot visualising the percentage of the specified binary response across the chosen variables. The plot includes comparisons for total responses and, if specified, grouped responses.
Details
The function first validates the binary nature of the specified variables and then
prepares the data for visualisation. The resulting plot shows the proportion of the
specified binary response (value
) for each variable in vars
. When a group
variable is provided, the plot includes facet-wrapped comparisons across groups.
Examples
if (FALSE) { # \dontrun{
# Example: Visualise binary survey responses by gender
vars <- list(Q1a = "Art", Q1b = "Automobiles", Q1c = "Birdwatching")
df <- plot_binary(dataset, vars = vars, value = "Yes", group = "gender", weight = "wgtvar")
} # }