Learn R Programming

sjPlot (version 2.0.0)

sjp.stackfrq: Plot stacked proportional bars

Description

Plot items (variables) of a scale as stacked proportional bars. This function is useful when several items with identical scale/categoroies should be plotted to compare the distribution of answers.

Usage

sjp.stackfrq(items, title = NULL, legend.title = NULL,
  legend.labels = NULL, axis.titles = NULL, axis.labels = NULL,
  weight.by = NULL, sort.frq = NULL, wrap.title = 50, wrap.labels = 30,
  wrap.legend.title = 30, wrap.legend.labels = 28, geom.size = 0.5,
  geom.colors = "Blues", show.values = TRUE, show.n = TRUE,
  show.prc = TRUE, show.legend = TRUE, grid.breaks = 0.2,
  expand.grid = FALSE, digits = 1, vjust = "center", 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).

See Also

  • http://www.strengejacke.de/sjPlot/sjp.stackfrq/{sjPlot manual: sjp.stackfrq}
  • sjt.stackfrq

Examples

Run this code
# random data for 4-category likert scale, 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("Independent", "Slightly dependent", 
              "Dependent", "Severely dependent")

# plot stacked frequencies of 5 (ordered) item-scales
sjp.stackfrq(likert_4, legend.labels = levels_4)

# -------------------------------
# Data from the EUROFAMCARE sample dataset
# -------------------------------
library(sjmisc)
data(efc)
# recveive first item of COPE-index scale
start <- which(colnames(efc) == "c82cop1")
# recveive first item of COPE-index scale
end <- which(colnames(efc) == "c90cop9")
# auto-detection of labels
sjp.stackfrq(efc[, c(start:end)])

Run the code above in your browser using DataLab