Learn R Programming

sjPlot (version 1.7)

sjt.corr: Show correlations as HTML table

Description

Shows the results of a computed correlation as HTML table. Requires either a data frame or a computed cor-object.

Usage

sjt.corr(data, missingDeletion = "pairwise", corMethod = "spearman",
  title = NULL, showPValues = TRUE, pvaluesAsNumbers = FALSE,
  fadeNS = TRUE, file = NULL, varlabels = NULL, breakLabelsAt = 40,
  digits = 3, triangle = "both", val.rm = NULL, stringDiagonal = NULL,
  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

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

Examples

Run this code
# create data frame with 5 random variables
df <- as.data.frame(cbind(rnorm(10),
                          rnorm(10),
                          rnorm(10),
                          rnorm(10),
                          rnorm(10)))

# plot correlation matrix using circles
sjt.corr(df)

# -------------------------------
# Data from the EUROFAMCARE sample dataset
# -------------------------------
data(efc)

# retrieve variable and value labels
varlabs <- get_var_labels(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
df <- as.data.frame(efc[, c(start : end)])
colnames(df) <- varlabs[c(start : end)]

# we have high correlations here, because all items
# belong to one factor. See example from "sjp.pca".
sjt.corr(df, pvaluesAsNumbers = TRUE)

# -------------------------------
# auto-detection of labels, only lower triangle
# -------------------------------
efc <- set_var_labels(efc, varlabs)
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
# -------------------------------
efc <- set_var_labels(efc, varlabs)
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
# -------------------------------
efc <- set_var_labels(efc, varlabs)
sjt.corr(efc[, c(start : end)],
         triangle = "lower",
         val.rm = 0.3,
         CSS = list(css.valueremove = 'color:blue;'))

Run the code above in your browser using DataLab