
Visualise Likert Scales with Stacked, Divergent, and Facetted Bar Plots
Source:R/plot_likert.R
plot_likert.Rd
plot_likert
generates various types of Likert plots (stacked, divergent, or facetted) for visualising
survey data, handling different configurations of data presentation including NET scores and custom ordering.
Usage
plot_likert(
data,
vars,
varLevels = NULL,
group = NULL,
weight = NULL,
type = c("stacked", "divergent", "facetted"),
neutrals = c("no_change", "right", "exclude"),
total = FALSE,
NET = FALSE,
addLabels = FALSE,
threshold = 0,
title = NULL,
subtitle = NULL,
order_by = NULL,
colours = NULL,
legend = c("top", "right", "left", "bottom", "none"),
nrow = 1,
ncol = 3,
width = 0.8,
ratio = 6,
base_size = 10,
base_font = ""
)
Arguments
- data
A data frame containing survey data.
- vars
A vector of variables containing Likert responses. If
group
is specified,vars
should only contain a single variable.- varLevels
A vector or a named list with 'left', 'neutral', and 'right' elements specifying the levels of the Likert scale.
- group
An optional grouping variable for creating facetted plots.
- weight
An optional weighting variable for the survey data.
- type
The type of Likert plot to generate: 'stacked', 'divergent', or 'facetted'.
- neutrals
Handling of neutral responses in the plot, can be 'no_change', 'right', or 'exclude'.
- total
If TRUE and
group
is specified, includes an option for the total population alongside group-specific plots.- NET
If TRUE, calculates and includes a Net Rating Score (difference between positive and negative responses).
- addLabels
if TRUE, adds % labels to the plot.
- threshold
A numeric value to adjust the threshold for labels to be shown.
- title
The title of the plot.
- subtitle
The subtitle of the plot.
- order_by
Specifies how to order responses in the plot. Can be NULL or based on 'left', 'right', or 'NET' responses.
- colours
A named vector of colours for plotting variables. Default uses
colour_pal("divRedBlue")
.- legend
Position of the legend ('top', 'right', 'left', 'bottom', or 'none').
- nrow
Number of rows in the legend, applicable when
legend
is 'top' or 'bottom'.- ncol
Number of columns to use when facetting the plot by
group
, applicable for 'facetted' plot type.- width
Width of the bars in the plot, applicable to 'stacked' and 'divergent' plot types.
- ratio
Aspect ratio of the plot, influencing the spacing and layout of plot elements.
- base_size
Base font size for text elements within the plot.
- base_font
Base font family for text elements within the plot.
Examples
if (FALSE) { # \dontrun{
data <- survey_data
vars <- c("Q1", "Q2")
varLevels <- list(left = c("Strongly Disagree", "Disagree"),
neutral = "Neutral",
right = c("Agree", "Strongly Agree"))
plot_likert(data, vars, varLevels, type = "divergent",
group = "DemographicGroup", NET = TRUE, order_by = "right")
} # }