Learn R Programming

sjPlot (version 2.0.0)

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

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

http://www.strengejacke.de/sjPlot/sjp.likert/{sjPlot manual: sjp.likert}

Examples

Run this code
# prepare data for dichotomous likert scale, 5 items
likert_2 <- data.frame(
  as.factor(sample(1:2, 500, replace = TRUE, prob = c(0.3,0.7))),
  as.factor(sample(1:2, 500, replace = TRUE, prob = c(0.6,0.4))),
  as.factor(sample(1:2, 500, replace = TRUE, prob = c(0.25,0.75))),
  as.factor(sample(1:2, 500, replace = TRUE, prob = c(0.9,0.1))),
  as.factor(sample(1:2, 500, replace = TRUE, prob = c(0.35,0.65))))
  
# create labels
levels_2 <- c("Agree", "Disagree")
                       
# prepare data for 4-category likert scale, with neutral category 5 items
Q1 <- as.factor(sample(1:4, 500, replace = TRUE, prob = c(0.2, 0.3, 0.1, 0.4)))
Q2 <- as.factor(sample(1:4, 500, replace = TRUE, prob = c(0.5, 0.25, 0.15, 0.1)))
Q3 <- as.factor(sample(1:4, 500, replace = TRUE, prob = c(0.25, 0.1, 0.4, 0.25)))
Q4 <- as.factor(sample(1:4, 500, replace = TRUE, prob = c(0.1, 0.4, 0.4, 0.1)))
Q5 <- as.factor(sample(1:4, 500, replace = TRUE, prob = c(0.35, 0.25, 0.15, 0.25)))

likert_4 <- data.frame(Q1, Q2, Q3, Q4, Q5)

# create labels
levels_4 <- c("Strongly agree", "Agree", "Disagree", 
              "Strongly Disagree", "Don't know")

# prepare data for 6-category likert scale, 5 items
likert_6 <- data.frame()

Q1 <- as.factor(sample(1:6, 500, replace = TRUE, prob = c(0.2,0.1,0.1,0.3,0.2,0.1)))
Q2 <- as.factor(sample(1:6, 500, replace = TRUE, prob = c(0.15,0.15,0.3,0.1,0.1,0.2)))
Q3 <- as.factor(sample(1:6, 500, replace = TRUE, prob = c(0.2,0.25,0.05,0.2,0.2,0.2)))
Q4 <- as.factor(sample(1:6, 500, replace = TRUE, prob = c(0.2,0.1,0.1,0.4,0.1,0.1)))
Q5 <- as.factor(sample(1:6, 500, replace = TRUE, prob = c(0.1,0.4,0.1,0.3,0.05,0.15)))

likert_6 <- data.frame(Q1, Q2, Q3, Q4, Q5)

# create labels
levels_6 <- c("Very strongly agree", "Strongly agree", "Agree",
              "Disagree", "Strongly disagree", "Very strongly disagree")

# create item labels
items <- c("Q1", "Q2", "Q3", "Q4", "Q5")

# plot dichotomous likert scale, ordered by "negative" values
sjp.likert(likert_2, geom.colors = c("green", "red"), legend.labels = levels_2, 
           axis.labels = items, sort.frq = "neg.desc")

# plot 4-category-likert-scale, no order
sjp.likert(likert_4, cat.neutral = 5, legend.labels = levels_4, 
           axis.labels = items, grid.range = 1.2, expand.grid = FALSE,
           values = "sum.outside", show.prc.sign = TRUE)

# plot 6-category-likert-scale, ordered by positive values,
# in brown color scale
sjp.likert(likert_6,  legend.labels = levels_6, axis.labels = items, 
           sort.frq = "pos.asc", digits = 0, show.prc.sign = TRUE,
           values = "sum.inside")

Run the code above in your browser using DataLab