Learn R Programming

sjPlot (version 1.7)

sjt.xtab: Show contingency tables as HTML table

Description

Shows contingency tables as HTML file in browser or viewer pane, or saves them as file.

Usage

sjt.xtab(var.row, var.col, var.grp = NULL, weightBy = NULL, digits = 1,
  file = NULL, variableLabels = NULL, valueLabels = NULL,
  breakVariableLabelsAt = 40, breakValueLabelsAt = 20,
  stringTotal = "Total", showObserved = TRUE, showCellPerc = FALSE,
  showRowPerc = FALSE, showColPerc = FALSE, showExpected = FALSE,
  showTotalN = FALSE, showHorizontalLine = FALSE, showSummary = TRUE,
  showLegend = TRUE, showNA = FALSE, labelNA = "NA", tdcol.n = "black",
  tdcol.expected = "#339999", tdcol.cell = "#993333",
  tdcol.row = "#333399", tdcol.col = "#339933", highlightTotal = FALSE,
  highlightColor = "#f8f8f8", percSign = " %", hundret = "100.0",
  encoding = NULL, CSS = NULL, useViewer = TRUE, no.output = FALSE,
  remove.spaces = TRUE)

Arguments

Value

Invisibly returns a structure with
  • 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.

See Also

Examples

Run this code
# prepare sample data set
data(efc)
efc.labels <- get_val_labels(efc)

# print simple cross table w/o labels
sjt.xtab(efc$e16sex, efc$e42dep)

# print cross table with labels and expected values
sjt.xtab(efc$e16sex,
         efc$e42dep,
         variableLabels = c("Elder's gender",
                            "Elder's dependency"),
         valueLabels = list(efc.labels[['e16sex']],
                            efc.labels[['e42dep']]),
         showExpected = TRUE)

# print minimal cross table with labels, total col/row highlighted
sjt.xtab(efc$e16sex, efc$e42dep,
         variableLabels = c("Elder's gender", "Elder's dependency"),
         valueLabels = list(efc.labels[['e16sex']], efc.labels[['e42dep']]),
         showHorizontalLine = FALSE,
         showCellPerc = FALSE,
         highlightTotal = TRUE)

# -------------------------------
# auto-detection of labels
# -------------------------------
efc <- set_var_labels(efc, get_var_labels(efc))
# print cross table with labels and all percentages
sjt.xtab(efc$e16sex, efc$e42dep,
         showRowPerc = TRUE, showColPerc = TRUE)

# print cross table with labels and all percentages, including
# grouping variable
sjt.xtab(efc$e16sex, efc$e42dep, efc$c161sex,
         variableLabels=c("Elder's gender",
                          "Elder's dependency",
                          "Carer's gender"),
         valueLabels=list(efc.labels[['e16sex']],
                          efc.labels[['e42dep']],
                          efc.labels[['c161sex']]),
         showRowPerc=TRUE, showColPerc=TRUE)

# ----------------------------------------------------------------
# User defined style sheet
# ----------------------------------------------------------------
sjt.xtab(efc$e16sex, efc$e42dep,
         variableLabels=c("Elder's gender", "Elder's dependency"),
         valueLabels=list(efc.labels[['e16sex']], efc.labels[['e42dep']]),
         CSS=list(css.table="border: 2px solid;",
                 css.tdata="border: 1px solid;",
                 css.horline="border-bottom: double blue;"))

Run the code above in your browser using DataLab