Learn R Programming

sjPlot (version 2.0.0)

sjp.corr: Plot correlation matrix

Description

Plot correlation matrix as ellipses or tiles.

Usage

sjp.corr(data, title = NULL, axis.labels = NULL, type = c("circle",
  "tile"), sort.corr = TRUE, decimals = 3, na.deletion = c("listwise",
  "pairwise"), corr.method = c("spearman", "pearson", "kendall"),
  geom.colors = "RdBu", geom.size = 15, wrap.title = 50,
  wrap.labels = 20, show.legend = FALSE, legend.title = NULL,
  show.values = TRUE, show.p = TRUE, p.numeric = FALSE,
  prnt.plot = 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).

Details

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.

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", show.legend = TRUE)

# -------------------------------
# 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