plot_correlation_heatmap | R Documentation |
Generates a heatmap of the upper triangle of a correlation matrix.
plot_correlation_heatmap(
x,
ttl = "Correlation matrix",
labels = NULL,
lyt = NULL,
gradient = c("#E69F00", "#56B4E9"),
txtSz = 1.25,
mc_adjust = "BH",
cut_off = 0.05,
new = T,
H = 20/3,
W = 25/3,
abbr_labels = TRUE,
status = FALSE
)
x |
A data frame (all variables will be used when generating the correlation matrix). |
ttl |
An optional title for the figure. |
labels |
The labels for the rows/columns. Users can pass a list with two character vectors of matching length to provide separate labels for rows and columns. |
lyt |
An optional matrix specifying the layout of the main panel (1) versus the side panel (2) with the color gradient. |
gradient |
The final end colors for the negative and positive correlations, respectively. |
txtSz |
The size of the text in the figure (a second value can be provided to adjust variable labels separately). |
mc_adjust |
The method to use when correcting for
multiple comparisons (see |
cut_off |
Cut-off for statistical significance. |
new |
Logical; if |
H |
The height in inches of the figure if a new plotting window is generated. |
W |
The width in inches of the figure if a new plotting window is generated. |
abbr_labels |
Logical; if |
status |
Logical; if |
A heatmap for the upper-triangle portion of the correlation matrix.
# Load data
data("mtcars")
x <- mtcars[, c(1,3,4,5,6,7)]
plot_correlation_heatmap( x, new = FALSE )
# Simulate a correlation matrix
# 5 x 5 matrix of random values
rand_mat <- matrix( rnorm(25), 5, 5 )
# Create covariance matrix by
# multiplying matrix by its transpose
cov_mat <- rand_mat %*% t( rand_mat )
corr_mat <- cov_mat/sqrt(diag(cov_mat)%*%t(diag(cov_mat)))
# Simulate data
x <- MASS::mvrnorm( 100, rep( 0, nrow( corr_mat ) ), corr_mat )
colnames( x ) <- paste0( 'V', 1:ncol( x ) )
x <- data.frame(x)
plot_correlation_heatmap( x, new = FALSE )
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.