tab_stackfrq | R Documentation |
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.).
tab_stackfrq(
items,
weight.by = NULL,
title = NULL,
var.labels = NULL,
value.labels = NULL,
wrap.labels = 20,
sort.frq = NULL,
alternate.rows = FALSE,
digits = 2,
string.total = "N",
string.na = "NA",
show.n = FALSE,
show.total = FALSE,
show.na = FALSE,
show.skew = FALSE,
show.kurtosis = FALSE,
digits.stats = 2,
file = NULL,
encoding = NULL,
CSS = NULL,
use.viewer = TRUE,
remove.spaces = TRUE
)
items |
Data frame, or a grouped data frame, with each column representing one item. |
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
|
title |
String, will be used as table caption. |
var.labels |
Character vector with variable names, which will be used to label variables in the output. |
value.labels |
Character vector (or |
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. |
sort.frq |
logical, indicates whether the
|
alternate.rows |
Logical, if |
digits |
Numeric, amount of digits after decimal point when rounding values. |
string.total |
label for the total N column. |
string.na |
label for the missing column/row. |
show.n |
logical, if |
show.total |
logical, if |
show.na |
logical, if |
show.skew |
logical, if |
show.kurtosis |
Logical, if |
digits.stats |
amount of digits for rounding the skewness and kurtosis valuess. Default is 2, i.e. skewness and kurtosis values have 2 digits after decimal point. |
file |
Destination file, if the output should be saved as file.
If |
encoding |
Character vector, indicating the charset encoding used
for variable and value labels. Default is |
CSS |
A |
use.viewer |
Logical, if |
remove.spaces |
Logical, if |
Invisibly returns
the web page style sheet (page.style
),
the web page content (page.content
),
the complete html-output (page.complete
) and
the html-table with inline-css for use with knitr (knitr
)
for further use.
# -------------------------------
# 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
## Not run:
if (interactive()) {
tab_stackfrq(likert_4, value.labels = levels_4, var.labels = items)
# -------------------------------
# Data from the EUROFAMCARE sample dataset
# Auto-detection of labels
# -------------------------------
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")
tab_stackfrq(efc[, c(start:end)], alternate.rows = TRUE)
tab_stackfrq(efc[, c(start:end)], alternate.rows = TRUE,
show.n = TRUE, show.na = TRUE)
# --------------------------------
# User defined style sheet
# --------------------------------
tab_stackfrq(efc[, c(start:end)], alternate.rows = TRUE,
show.total = TRUE, show.skew = TRUE, show.kurtosis = TRUE,
CSS = list(css.ncol = "border-left:1px dotted black;",
css.summary = "font-style:italic;"))
}
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.