Learn R Programming

sjPlot (version 1.8.1)

sjt.frq: Show frequencies as HTML table

Description

Shows (multiple) frequency tables as HTML file, or saves them as file.

Usage

sjt.frq(data, file = NULL, weightBy = NULL,
  weightByTitleString = " (weighted)", variableLabels = NULL,
  valueLabels = NULL, autoGroupAt = NULL, sort.frq = NULL,
  alternateRowColors = FALSE, stringValue = "value", stringCount = "N",
  stringPerc = "raw %", stringValidPerc = "valid %",
  stringCumPerc = "cumulative %", stringMissingValue = "missings",
  highlightMedian = FALSE, highlightQuartiles = FALSE,
  skipZeroRows = "auto", showSummary = TRUE, showSkew = FALSE,
  showKurtosis = FALSE, skewString = "γ",
  kurtosisString = "ω", digits = 2, removeStringVectors = TRUE,
  autoGroupStrings = TRUE, maxStringDist = 3, encoding = NULL,
  CSS = NULL, useViewer = TRUE, no.output = FALSE, remove.spaces = TRUE)

Arguments

Value

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

Details

How does the CSS-parameter work? With the CSS-paramater, the visual appearance of the tables can be modified. To get an overview of all style-sheet-classnames that are used in this function, see return value page.style for details. Parameters for this list have following syntax:
  1. the class-names with"css."-prefix as parameter name and
  2. each style-definition must end with a semicolon
You can add style information to the default styles by using a + (plus-sign) as initial character for the parameter attributes. Examples:
  • css.table='border:2px solid red;'for a solid 2-pixel table border in red.
  • css.summary='font-weight:bold;'for a bold fontweight in the summary row.
  • css.lasttablerow='border-bottom: 1px dotted blue;'for a blue dotted border of the last table row.
  • css.colnames='+color:green'to add green color formatting to column names.
  • css.arc='color:blue;'for a blue text color each 2nd row.
  • css.caption='+color:red;'to add red font-color to the default table caption style.
See further examples at http://www.strengejacke.de/sjPlot/sjtbasics{sjPlot manual: sjt-basics}.

See Also

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

Examples

Run this code
# load sample data
library(sjmisc)
data(efc)

# retrieve value and variable labels
variables <- get_var_labels(efc)
values <- get_val_labels(efc)

# show frequencies of "e42dep" in RStudio Viewer Pane
# or default web browser
sjt.frq(efc$e42dep)

# plot and show frequency table of "e42dep" with labels
sjt.frq(efc$e42dep,
        variableLabels = variables['e42dep'],
        valueLabels = values[['e42dep']])

# plot frequencies of e42dep, e16sex and c172code in one HTML file
# and show table in RStudio Viewer Pane or default web browser
# Note that valueLabels of multiple variables have to be
# list-objects
sjt.frq(data.frame(efc$e42dep, efc$e16sex, efc$c172code),
        variableLabels = c(variables['e42dep'],
                           variables['e16sex'],
                           variables['c172code']),
        valueLabels = list(values[['e42dep']],
                           values[['e16sex']],
                           values[['c172code']]))


# -------------------------------
# auto-detection of labels
# due to auto-detection of labels, this works as well
# -------------------------------
sjt.frq(data.frame(efc$e42dep, efc$e16sex, efc$c172code))


# plot larger scale including zero-counts
# indicating median and quartiles
sjt.frq(efc$neg_c_7,
        variableLabels = variables['neg_c_7'],
        valueLabels = values[['neg_c_7']],
        highlightMedian = TRUE,
        highlightQuartiles = TRUE)

# -------------------------------
# sort frequencies
# -------------------------------
sjt.frq(efc$e42dep, sort.frq = "desc")

# --------------------------------
# User defined style sheet
# --------------------------------
sjt.frq(efc$e42dep,
        variableLabels = variables['e42dep'],
        valueLabels = values[['e42dep']],
        CSS = list(css.table = "border: 2px solid;",
                   css.tdata = "border: 1px solid;",
                   css.firsttablecol = "color:#003399; font-weight:bold;"))

Run the code above in your browser using DataLab