Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

corrRect

Draw rectangle(s) on the correlation matrix graph.


Description

Draw rectangle(s) around the chart of corrrlation matrix.

Usage

corrRect(clus, col = "black", lwd = 2)

Arguments

clus

Vector, the number of each cluster's members.

col

Color of rectangles.

lwd

Line width of rectangles.

Details

corrRect needs the number(parameter clus) of each cluster's members, while corrRect.hclust can get the members in each cluster based on hierarchical clustering (hclust).

Author(s)

Taiyun Wei

Examples

data(mtcars)
M <- cor(mtcars)
corrplot(M, method = "circle", order = "FPC")
corrRect(c(5,6))

(order.hc <- corrMatOrder(M, order = "hclust"))
(order.hc2 <- corrMatOrder(M, order = "hclust", hclust.method = "ward.D"))
M.hc  <- M[order.hc, order.hc]
M.hc2 <- M[order.hc2, order.hc2]

par(ask = TRUE)

# same as: corrplot(M, order = "hclust", addrect = 2)
corrplot(M.hc)
corrRect.hclust(corr = M.hc, k = 2)

# same as: corrplot(M, order = "hclust", addrect = 3)
corrplot(M.hc)
corrRect.hclust(corr = M.hc, k = 3)

# same as: corrplot(M, order = "hclust", hclust.method = "ward.D", addrect = 2)
corrplot(M.hc2)
corrRect.hclust(M.hc2, k = 2, method = "ward.D")

# same as: corrplot(M, order = "hclust", hclust.method = "ward.D", addrect = 3)
corrplot(M.hc2)
corrRect.hclust(M.hc2, k = 3, method = "ward.D")

# same as: corrplot(M, order = "hclust", hclust.method = "ward.D", addrect = 4)
corrplot(M.hc2)
corrRect.hclust(M.hc2, k = 4, method = "ward.D")

corrplot

Visualization of a Correlation Matrix

v0.88
MIT + file LICENSE
Authors
Taiyun Wei [cre, aut], Viliam Simko [aut], Michael Levy [ctb], Yihui Xie [ctb], Yan Jin [ctb], Jeff Zemla [ctb], Moritz Freidank [ctb], Jun Cai [ctb], Tomas Protivinsky [ctb]
Initial release
2021-05-11

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.