所以我尝试使用R&#39 corrplot
包创建关联矩阵。我想在文本标签中使用两种颜色,以显示变量组。
举个简单的例子:
dat <- data.frame("Blue" = c(1:20), "Red" = sample(1:20, 20, replace = T))
dat <- as.matrix(dat)
C = rcorr(dat, type = "pearson")
corrplot(corr = C$r, order = "original", title = "Pearson Correlations", method = "color", type = "full", p.mat=C$P, insig = "blank", tl.col = "blue", addgrid.col = "darkgrey", bg = "white", cl.pos = "b", tl.pos = "tl", col = colorRampPalette(c("darkred","white","midnightblue"))(100), mar = c(4, 0, 4, 0))
我知道tl.col
是标题颜色的参数,但我想将两个变量更改为彼此具有不同的颜色,并且无法在文档中找到此选项。这可能吗?
答案 0 :(得分:1)
您可以使用合并功能c()
为不同的列输入不同的颜色标签。
library(corrplot)
library(Hmisc)
# defining dataframe
dat <-
data.frame("Blue" = c(1:20),
"Red" = sample(1:20, 20, replace = T))
# getting correlations
C = Hmisc::rcorr(as.matrix(dat), type = "pearson")
# preparing the plot
corrplot::corrplot(
corr = C$r,
order = "original",
title = "Pearson Correlations",
method = "color",
type = "full",
p.mat = C$P,
insig = "blank",
tl.col = c("blue", "red"), # different colors
addgrid.col = "darkgrey",
bg = "white",
cl.pos = "b",
tl.pos = "tl",
col = colorRampPalette(c("darkred", "white", "midnightblue"))(100),
mar = c(4, 0, 4, 0)
)
由reprex package(v0.2.0)创建于2018-02-20。