Learn R Programming

sjPlot (version 1.8.3)

sjp.corr: Plot correlation matrix

Description

Plot correlation matrix as ellipses or tiles. Required argument is either a data.frame or a matrix with correlation coefficients as returned by the cor-function. 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 darker.

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, showValueLabels = TRUE, showPValues = 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
mydf <- data.frame(cbind(runif(10),
                         runif(10),
                         runif(10),
                         runif(10),
                         runif(10)))

# plot correlation matrix using circles
sjp.corr(mydf)

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


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

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

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

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

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

Run the code above in your browser using DataLab