[英]How can I include multiple colours in the text labels for a correlation matrix in R corrplot?
所以我正在嘗試使用R的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
是標題顏色的參數,但我想將兩個變量更改為彼此具有不同的顏色,並且無法在文檔中找到此選項。 這可能嗎?
您可以只使用合並函數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軟件包 (v0.2.0)創建於2018-02-20。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.