Learn R Programming

sjPlot (version 2.1.0)

sjt.corr: Summary of correlations as HTML table

Description

Shows the results of a computed correlation as HTML table. Requires either a data.frame or a matrix with correlation coefficients as returned by the cor-function.

Usage

sjt.corr(data, na.deletion = c("listwise", "pairwise"), corr.method = c("spearman", "pearson", "kendall"), title = NULL, var.labels = NULL, wrap.labels = 40, show.p = TRUE, p.numeric = FALSE, fade.ns = TRUE, val.rm = NULL, digits = 3, triangle = "both", string.diag = NULL, CSS = NULL, encoding = NULL, file = NULL, use.viewer = TRUE, no.output = FALSE, remove.spaces = TRUE)

Arguments

data
variables which frequencies should be printed as table. Either use a single variable (vector) or a data frame where each column represents a variable (see 'Examples').
na.deletion
indicates how missing values are treated. May be either "listwise" (default) or "pairwise". May be abbreviated.
corr.method
indicates the correlation computation method. May be one of "spearman" (default), "pearson" or "kendall". May be abbreviated.
title
table caption. By default, title = NULL, hence no title will be used.
var.labels
character vector with variable names, which will be used to label variables in the output.
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.
show.p
logical, adds significance levels to values, or value and variable labels.
p.numeric
logical, if TRUE, the p-values are printed as numbers. If FALSE (default), asterisks are used.
fade.ns
logical, if TRUE (default), non-significant correlation-values appear faded (by using a lighter grey text color). See 'Note'.
val.rm
specify a number between 0 and 1 to suppress the output of correlation values that are smaller than val.rm. The absolute correlation values are used, so a correlation value of -.5 would be greater than val.rm = .4 and thus not be omitted. By default, this argument is NULL, hence all values are shown in the table. If a correlation value is below the specified value of val.rm, it is still printed to the HTML table, but made "invisible" with white foreground color. You can use the CSS argument ("css.valueremove") to change color and appearance of those correlation value that are smaller than the limit specified by val.rm.
digits
numeric, amount of digits after decimal point when rounding estimates and values.
triangle
indicates whether only the upper right (use "upper"), lower left (use "lower") or both (use "both") triangles of the correlation table is filled with values. Default is "both". You can specifiy the inital letter only.
string.diag
a vector with string values of the same length as ncol(data) (number of correlated items) that can be used to display content in the diagonal cells where row and column item are identical (i.e. the "self-correlation"). By defauilt, this argument is NULL and the diagnal cells are empty.
CSS
list-object with user-defined style-sheet-definitions, according to the official CSS syntax. See 'Details'.
encoding
string, indicating the charset encoding used for variable and value labels. Default is NULL, so encoding will be auto-detected depending on your platform (e.g., "UTF-8" for Unix and "Windows-1252" for Windows OS). Change encoding if specific chars are not properly displayed (e.g. German umlauts).
file
destination file, if the output should be saved as file. If NULL (default), the output will be saved as temporary file and openend either in the IDE's viewer pane or the default web browser.
use.viewer
If TRUE, the HTML table is shown in the IDE's viewer pane. If FALSE or no viewer available, the HTML table is opened in a web browser.
no.output
logical, if TRUE, the html-output is neither opened in a browser nor shown in the viewer pane and not even saved to file. This option is useful when the html output should be used in knitr documents. The html output can be accessed via the return value.
remove.spaces
logical, if 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
  • 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
## Not run: 
# # plot correlation matrix using circles
# sjt.corr(mydf)
# 
# # Data from the EUROFAMCARE sample dataset
# library(sjmisc)
# data(efc)
# 
# # retrieve variable and value labels
# varlabs <- get_label(efc)
# 
# # recveive first item of COPE-index scale
# start <- which(colnames(efc) == "c83cop2")
# # recveive last item of COPE-index scale
# end <- which(colnames(efc) == "c88cop7")
#  
# # create data frame with COPE-index scale
# mydf <- data.frame(efc[, c(start:end)])
# colnames(mydf) <- varlabs[c(start:end)]
# 
# # we have high correlations here, because all items
# # belong to one factor. See example from "sjp.pca". 
# sjt.corr(mydf, p.numeric = TRUE)
# 
# # auto-detection of labels, only lower triangle
# sjt.corr(efc[, c(start:end)], triangle = "lower")
# 
# # auto-detection of labels, only lower triangle, all correlation 
# # values smaller than 0.3 are not shown in the table
# sjt.corr(efc[, c(start:end)], triangle = "lower", val.rm = 0.3)
# 
# # auto-detection of labels, only lower triangle, all correlation 
# # values smaller than 0.3 are printed in blue
# sjt.corr(efc[, c(start:end)], triangle = "lower",val.rm = 0.3, 
#          CSS = list(css.valueremove = 'color:blue;'))## End(Not run)

Run the code above in your browser using DataLab