Learn R Programming

sjPlot (version 1.7)

sjp.likert: Plot likert scales as centered stacked bars

Description

Plot likert scales as centered stacked bars.

Usage

sjp.likert(items, catcount = NULL, cat.neutral = NULL, weightBy = NULL,
  weightByTitleString = NULL, sort.frq = NULL, geom.size = 0.6,
  geom.colors = "BrBG", reverse.colors = FALSE,
  cat.neutral.color = "grey70", intercept.line.color = "grey50",
  value.labels = "show", showPercentageSign = FALSE, legendLabels = NULL,
  hideLegend = FALSE, title = NULL, legendTitle = NULL, includeN = TRUE,
  showItemLabels = TRUE, axisLabels.y = NULL, breakTitleAt = 50,
  breakLabelsAt = 30, breakLegendTitleAt = 30, breakLegendLabelsAt = 28,
  gridRange = 1, gridBreaksAt = 0.2, expand.grid = TRUE,
  axisTitle.x = NULL, axisTitle.y = NULL, coord.flip = TRUE,
  printPlot = 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

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
likert_4 <- data.frame(as.factor(sample(1:5, 500, replace=TRUE,
                                        prob=c(0.2,0.3,0.1,0.35,0.05))),
                       as.factor(sample(1:5, 500, replace=TRUE,
                                        prob=c(0.5,0.25,0.15,0.1,0.0))),
                       as.factor(sample(1:5, 500, replace=TRUE,
                                        prob=c(0.25,0.1,0.38,0.24,0.03))),
                       as.factor(sample(1:5, 500, replace=TRUE,
                                        prob=c(0.1,0.32,0.37,0.1,0.11))),
                       as.factor(sample(1:5, 500, replace=TRUE,
                                        prob=c(0.35,0.22,0.15,0.25, 0.03))))
# 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(
               as.factor(sample(1:6, 500, replace=TRUE, prob=c(0.2,0.1,0.1,0.3,0.2,0.1))),
               as.factor(sample(1:6, 500, replace=TRUE, prob=c(0.15,0.15,0.3,0.1,0.1,0.2))),
               as.factor(sample(1:6, 500, replace=TRUE, prob=c(0.2,0.25,0.05,0.2,0.2,0.2))),
               as.factor(sample(1:6, 500, replace=TRUE, prob=c(0.2,0.1,0.1,0.4,0.1,0.1))),
               as.factor(sample(1:6, 500, replace=TRUE, prob=c(0.1,0.4,0.1,0.3,0.05,0.15))))
# 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"),
           legendLabels = levels_2,
           axisLabels.y = items,
           sort.frq = "neg.desc")

# plot 4-category-likert-scale, no order
sjp.likert(likert_4,
           cat.neutral = 5,
           legendLabels = levels_4,
           axisLabels.y = items,
           gridRange = 1.2,
           expand.grid = FALSE,
           value.labels = "sum.outside",
           showPercentageSign = TRUE)

# plot 6-category-likert-scale, ordered by positive values,
# in brown color scale
sjp.likert(likert_6,
           legendLabels = levels_6,
           axisLabels.y = items,
           sort.frq = "pos.asc",
           value.labels = "sum.inside")

Run the code above in your browser using DataLab