Learn R Programming

sjPlot (version 1.8.1)

sjt.stackfrq: Show stacked frequencies as HTML table

Description

Shows the results of stacked frequencies (such as likert scales) as HTML table. This function is useful when several items with identical scale/categories should be printed as table to compare their distributions (e.g. when plotting scales like SF, Barthel-Index, Quality-of-Life-scales etc.).

Usage

sjt.stackfrq(items, weightBy = NULL, title = NULL, varlabels = NULL,
  breakLabelsAt = 40, valuelabels = NULL, breakValueLabelsAt = 20,
  sort.frq = NULL, alternateRowColors = FALSE, digits = 2,
  showN = FALSE, showTotalN = FALSE, showNA = FALSE, labelNA = "NA",
  showSkew = FALSE, showKurtosis = FALSE, digits.stats = 2,
  skewString = "Skew", kurtosisString = "Kurtosis", file = NULL,
  encoding = NULL, CSS = NULL, useViewer = TRUE, no.output = FALSE,
  remove.spaces = TRUE)

Arguments

Value

Invisibly returns
  • the web page style sheet (page.style),
  • the web page content (page.content),
  • the complete html-output (output.complete) and
  • the html-table with inline-css for use with knitr (knitr)
for further use.

Details

See 'Details' in sjt.frq.

See Also

Examples

Run this code
# -------------------------------
# random sample
# -------------------------------
# prepare data for 4-category likert scale, 5 items
likert_4 <- data.frame(as.factor(sample(1:4,
                                        500,
                                        replace = TRUE,
                                        prob = c(0.2, 0.3, 0.1, 0.4))),
                       as.factor(sample(1:4,
                                        500,
                                        replace = TRUE,
                                        prob = c(0.5, 0.25, 0.15, 0.1))),
                       as.factor(sample(1:4,
                                        500,
                                        replace = TRUE,
                                        prob = c(0.25, 0.1, 0.4, 0.25))),
                       as.factor(sample(1:4,
                                        500,
                                        replace = TRUE,
                                        prob = c(0.1, 0.4, 0.4, 0.1))),
                       as.factor(sample(1:4,
                                        500,
                                        replace = TRUE,
                                        prob = c(0.35, 0.25, 0.15, 0.25))))
# create labels
levels_4 <- c("Independent",
              "Slightly dependent",
              "Dependent",
              "Severely dependent")

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

# plot stacked frequencies of 5 (ordered) item-scales
sjt.stackfrq(likert_4, valuelabels = levels_4, varlabels = items)


# -------------------------------
# Data from the EUROFAMCARE sample dataset
# Auto-detection of labels
# -------------------------------
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")

sjt.stackfrq(efc[, c(start:end)],
             alternateRowColors = TRUE)

sjt.stackfrq(efc[, c(start:end)],
             alternateRowColors = TRUE,
             showN = TRUE,
             showNA = TRUE)


# --------------------------------
# User defined style sheet
# --------------------------------
sjt.stackfrq(efc[, c(start:end)],
             alternateRowColors = TRUE,
             showTotalN = TRUE,
             showSkew = TRUE,
             showKurtosis = TRUE,
             CSS = list(css.ncol = "border-left:1px dotted black;",
                        css.summary = "font-style:italic;"))

Run the code above in your browser using DataLab