Learn R Programming

sjPlot (version 2.3.3)

sjp.likert: Plot likert scales as centered stacked bars

Description

Plot likert scales as centered stacked bars.

Usage

sjp.likert(items, title = NULL, legend.title = NULL, legend.labels = NULL,
  axis.titles = NULL, axis.labels = NULL, catcount = NULL,
  cat.neutral = NULL, sort.frq = NULL, weight.by = NULL,
  title.wtd.suffix = NULL, wrap.title = 50, wrap.labels = 30,
  wrap.legend.title = 30, wrap.legend.labels = 28, geom.size = 0.6,
  geom.colors = "BrBG", cat.neutral.color = "grey70",
  intercept.line.color = "grey50", reverse.colors = FALSE,
  values = "show", show.n = TRUE, show.legend = TRUE,
  show.prc.sign = FALSE, grid.range = 1, grid.breaks = 0.2,
  expand.grid = TRUE, digits = 1, coord.flip = TRUE, prnt.plot = TRUE)

Arguments

items

Data frame, with each column representing one item.

title

character vector, used as plot title. Depending on plot type and function, will be set automatically. If title = "", no title is printed. For effect-plots, may also be a character vector of length > 1, to define titles for each sub-plot or facet.

legend.title

character vector, used as title for the plot legend.

legend.labels

character vector with labels for the guide/legend.

axis.titles

character vector of length one or two, defining the title(s) for the x-axis and y-axis.

axis.labels

character vector with labels used as axis labels. Optional argument, since in most cases, axis labels are set automatically.

catcount

Optional, amount of categories of items (e.g. "strongly disagree", "disagree", "agree" and "strongly agree" would be catcount = 4). Note that this argument only applies to "valid" answers, i.e. if you have an additional neutral category (see cat.neutral) like "don't know", this won't count for catcount (e.g. "strongly disagree", "disagree", "agree", "strongly agree" and neutral category "don't know" would still mean that catcount = 4). See 'Note'.

cat.neutral

If there's a neutral category (like "don't know" etc.), specify the index number (value) for this category. Else, set cat.neutral = NULL (default). The proportions of neutral category answers are plotted as grey bars on the left side of the figure.

sort.frq

Indicates whether the items of items should be ordered by total sum of positive or negative answers.

"pos.asc"

to order ascending by sum of positive answers

"pos.desc"

to order descending by sum of positive answers

"neg.asc"

for sorting ascending negative answers

"neg.desc"

for sorting descending negative answers

NULL

(default) for no sorting

weight.by

Vector of weights that will be applied to weight all cases. Must be a vector of same length as the input vector. Default is NULL, so no weights are used.

title.wtd.suffix

Suffix (as string) for the title, if weight.by is specified, e.g. title.wtd.suffix=" (weighted)". Default is NULL, so title will not have a suffix when cases are weighted.

wrap.title

numeric, determines how many chars of the plot title are displayed in one line and when a line break is inserted.

wrap.labels

numeric, determines how many chars of the value, variable or axis labels are displayed in one line and when a line break is inserted.

wrap.legend.title

numeric, determines how many chars of the legend's title are displayed in one line and when a line break is inserted.

wrap.legend.labels

numeric, determines how many chars of the legend labels are displayed in one line and when a line break is inserted.

geom.size

size resp. width of the geoms (bar width, line thickness or point size, depending on plot type and function). Note that bar and bin widths mostly need smaller values than dot sizes.

geom.colors

user defined color for geoms. See 'Details' in sjp.grpfrq.

cat.neutral.color

Color of the neutral category, if plotted (see cat.neutral).

intercept.line.color

Color of the vertical intercept line that divides positive and negative values.

reverse.colors

Logical, if TRUE, the color scale from geom.colors will be reversed, so positive and negative values switch colors.

values

Determines style and position of percentage value labels on the bars:

"show"

(default) shows percentage value labels in the middle of each category bar

"hide"

hides the value labels, so no percentage values on the bars are printed

"sum.inside"

shows the sums of percentage values for both negative and positive values and prints them inside the end of each bar

"sum.outide"

shows the sums of percentage values for both negative and positive values and prints them outside the end of each bar

show.n

logical, if TRUE, adds total number of cases for each group or category to the labels.

show.legend

logical, if TRUE, and depending on plot type and function, a legend is added to the plot.

show.prc.sign

Logical, if TRUE, %-signs for value labels are shown.

grid.range

Numeric, limits of the x-axis-range, as proportion of 100. Default is 1, so the x-scale ranges from zero to 100% on both sides from the center. You can use values beyond 1 (100%) in case bar labels are not printed because they exceed the axis range. E.g. grid.range = 1.4 will set the axis from -140 to +140%, however, only (valid) axis labels from -100 to +100% are printed. Neutral categories are adjusted to the most left limit.

grid.breaks

numeric; sets the distance between breaks for the axis, i.e. at every grid.breaks'th position a major grid is being printed.

expand.grid

logical, if TRUE, the plot grid is expanded, i.e. there is a small margin between axes and plotting region. Default is FALSE.

digits

Numeric, amount of digits after decimal point when rounding estimates and values.

coord.flip

logical, if TRUE, the x and y axis are swapped.

prnt.plot

logical, if TRUE (default), plots the results as graph. Use FALSE if you don't want to plot any graphs. In either case, the ggplot-object will be returned as value.

Value

(Insisibily) returns the ggplot-object with the complete plot (plot) as well as the data frame that was used for setting up the ggplot-object (df.neg for the negative values, df.pos for the positive values and df.neutral for the neutral category values).

See Also

sjPlot manual: sjp.likert

Examples

Run this code
# NOT RUN {
# Data from the EUROFAMCARE sample dataset
library(dplyr)
library(sjmisc)
data(efc)
# find all variables from COPE-Index, which all have a "cop" in their
# variable name, and then plot that subset as likert-plot
efc[, find_var(efc, "cop")] %>% sjp.likert()

sjp.likert(
  find_var(efc, "cop", as.df = TRUE),
  grid.range = 1.2,
  expand.grid = FALSE,
  values = "sum.outside",
  show.prc.sign = TRUE
)

# }

Run the code above in your browser using DataLab