1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176
|
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/tab_stackfrq.R
\name{tab_stackfrq}
\alias{tab_stackfrq}
\title{Summary of stacked frequencies as HTML table}
\usage{
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
)
}
\arguments{
\item{items}{Data frame, or a grouped data frame, with each column representing one item.}
\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
\code{NULL}, so no weights are used.}
\item{title}{String, will be used as table caption.}
\item{var.labels}{Character vector with variable names, which will be used
to label variables in the output.}
\item{value.labels}{Character vector (or \code{list} of character vectors)
with value labels of the supplied variables, which will be used
to label variable values in the output.}
\item{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.}
\item{sort.frq}{logical, indicates whether the \code{items} should be ordered by
by highest count of first or last category of \code{items}.
\itemize{
\item Use \code{"first.asc"} to order ascending by lowest count of first category,
\item \code{"first.desc"} to order descending by lowest count of first category,
\item \code{"last.asc"} to order ascending by lowest count of last category,
\item \code{"last.desc"} to order descending by lowest count of last category,
\item or \code{NULL} (default) for no sorting.
}}
\item{alternate.rows}{Logical, if \code{TRUE}, rows are printed in
alternatig colors (white and light grey by default).}
\item{digits}{Numeric, amount of digits after decimal point when rounding
values.}
\item{string.total}{label for the total N column.}
\item{string.na}{label for the missing column/row.}
\item{show.n}{logical, if \code{TRUE}, adds total number of cases for each
group or category to the labels.}
\item{show.total}{logical, if \code{TRUE}, an additional column with each
item's total N is printed.}
\item{show.na}{logical, if \code{TRUE}, \code{\link{NA}}'s (missing values)
are added to the output.}
\item{show.skew}{logical, if \code{TRUE}, an additional column with each item's skewness is printed.
The skewness is retrieved from the \code{\link[psych]{describe}}-function
of the \pkg{psych}-package.}
\item{show.kurtosis}{Logical, if \code{TRUE}, the kurtosis for each item will also be shown (see \code{\link[psych]{kurtosi}}
and \code{\link[psych]{describe}} in the \code{psych}-package for more details.}
\item{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.}
\item{file}{Destination file, if the output should be saved as file.
If \code{NULL} (default), the output will be saved as temporary file and
opened either in the IDE's viewer pane or the default web browser.}
\item{encoding}{Character vector, indicating the charset encoding used
for variable and value labels. Default is \code{"UTF-8"}. For Windows
Systems, \code{encoding = "Windows-1252"} might be necessary for proper
display of special characters.}
\item{CSS}{A \code{\link{list}} with user-defined style-sheet-definitions,
according to the \href{https://www.w3.org/Style/CSS/}{official CSS syntax}.
See 'Details' or \href{https://strengejacke.github.io/sjPlot/articles/table_css.html}{this package-vignette}.}
\item{use.viewer}{Logical, if \code{TRUE}, the HTML table is shown in the IDE's
viewer pane. If \code{FALSE} or no viewer available, the HTML table is
opened in a web browser.}
\item{remove.spaces}{Logical, if \code{TRUE}, leading spaces are removed from all lines in the final string
that contains the html-data. Use this, if you want to remove parantheses for html-tags. The html-source
may look less pretty, but it may help when exporting html-tables to office tools.}
}
\value{
Invisibly returns
\itemize{
\item the web page style sheet (\code{page.style}),
\item the web page content (\code{page.content}),
\item the complete html-output (\code{page.complete}) and
\item the html-table with inline-css for use with knitr (\code{knitr})
}
for further use.
}
\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.).
}
\examples{
# -------------------------------
# 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
\dontrun{
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;"))
}
}
}
|