Learn R Programming

sjPlot (version 1.7)

sjp.corr: Plot correlation matrix

Description

Plot correlations as ellipses or tiles. Required parameter is either a data frame or a computed cor-object. In case of ellipses, the ellipses size indicates the strength of the correlation. Furthermore, blue and red colors indicate positive or negative correlations, where stronger correlations are darkened.

Usage

sjp.corr(data, title = NULL, axisLabels = NULL, type = "circle",
  sortCorrelations = TRUE, decimals = 3, missingDeletion = "listwise",
  corMethod = "spearman", geom.colors = "RdBu", geom.size = 15,
  breakTitleAt = 50, breakLabelsAt = 20, hideLegend = TRUE,
  legendTitle = NULL, showCorrelationValueLabels = TRUE,
  showCorrelationPValues = TRUE, pvaluesAsNumbers = FALSE,
  printPlot = TRUE)

Arguments

Value

(Insisibily) returns the ggplot-object with the complete plot (plot) as well as the data frame that was used for setting up the ggplot-object (df) and the original correlation matrix (corr.matrix).

See Also

sjt.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
sjp.corr(df)

# plot correlation matrix using square tiles without diagram background
sjp.corr(df, type="tile")


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

# retrieve variable and value labels
varlabs <- get_var_labels(efc)

# create data frame
vars.index <- c(1, 4, 15, 19, 20, 21, 22, 24, 25)
df <- as.data.frame(efc[, vars.index])
colnames(df) <- varlabs[vars.index]

# show legend
sjp.corr(df, type="tile", hideLegend=FALSE)

# -------------------------------
# auto-detection of labels
# -------------------------------
efc <- set_var_labels(efc, varlabs)
# blank theme
sjp.setTheme(theme = "blank", axis.angle.x = 90)
sjp.corr(efc[, vars.index])

Run the code above in your browser using DataLab