更改 corrplot.mixed 中的文本颜色
Change text color in corrplot.mixed
在 r
包 corrplot
中,您可以在相关矩阵的下半部分和上半部分混合图形类型,以获得漂亮的视觉效果。我希望在矩阵的下半部分有数字,在矩阵的上半部分有省略号——这样就可以了。但是,根据我的数据,我看不到一些相关数字,因为它们接近 0。下面是我正在使用的代码和当前输出。
有没有办法改变矩阵下半部分的文本颜色?我想将相关系数的颜色更改为不是白色(它们不需要从红色变为蓝色,黑色也可以)。
#Saves the correlation matrix for reproducibility
#The matrix was modified based on the answer here:
cormatx <- structure(c(1, 0.480473436029381, 0.727971392165508, 0.0755790813842022,
0.647226624978262, 0.706156814758194, 0.73971915882987, 0.073024457099958,
0.480473436029381, 1, 0.540515552878261, 0.106196818240067, 0.505171500429873,
0.480694458288349, 0.538693541543583, 0.158300667842954, 0.727971392165508,
0.540515552878261, 1, 0.111168537597397, 0.587432598932939, 0.673406541830384,
0.724533755640279, 0.139232852746538, 0.0755790813842022, 0.106196818240067,
0.111168537597397, 1, -0.0844917222701804, 0.0382605955575862,
-0.00462812019681349, 0.000406894700952559, 0.647226624978262,
0.505171500429873, 0.587432598932939, -0.0844917222701804, 1,
0.668544141384562, 0.761303240927891, 0.152127182963817, 0.706156814758194,
0.480694458288349, 0.673406541830384, 0.0382605955575862, 0.668544141384562,
1, 0.772678948045676, 0.119611111043454, 0.73971915882987, 0.538693541543583,
0.724533755640279, -0.00462812019681349, 0.761303240927891, 0.772678948045676,
1, 0.174453831824302, 0.073024457099958, 0.158300667842954, 0.139232852746538,
0.000406894700952559, 0.152127182963817, 0.119611111043454, 0.174453831824302,
1), .Dim = c(8L, 8L), .Dimnames = list(c("A. SAT Critical Reading",
"B. SAT Mathematics", "C. SAT Writing Multiple Choice", "D. SAT Essay",
"E. TOEFL Listening Comprehension", "F. TOEFL Structure and Written Expression",
"G. TOEFL Reading Comprehension", "H. TOEFL Test of Written English"
), c("A", "B", "C", "D", "E", "F", "G", "H")))
#Creates the corrplot
corrplot.mixed(cormatx, upper = "ellipse", lower = "number",
tl.pos = "lt", tl.col = "black", tl.offset=1, tl.srt = 0)
他们在 ?corrplot
中有一个这样的例子(在 "circle + black number" 下)。看起来您必须调用 corrplot
两次:一次是先绘制椭圆(彩色),然后再次分别绘制系数(指定例如 colour=black),因为如果您在中指定 col="black"
corrplot.mixed
椭圆也是黑色的。
此外,如果您查看 corrplot.mixed
代码,您会发现它向 upper 和 lower 调用传递了相同的 ...
,这就是为什么指定例如colour="black"
到 corrplot.mixed
会将您的省略号和文本都绘制为黑色,而不仅仅是文本。
即
# draw ellipses + decorations
corrplot(cormatx, type="upper", method="ellipse",
tl.pos="lt", tl.col="black", tl.offset=1, tl.srt=0)
# draw labels in black (disabling all the other stuff already drawn)
corrplot(cormatx, add=T, type="lower", method="number",
col="black", diag=F, tl.pos="n", cl.pos="n")
# if you don't like the lines on the diagonal, (ie diag="n" of corrplot.mixed),
# having a look at corrplot.mixed yields the following code:
n <- nrow(cormatx)
symbols(1:n, n:1, add=TRUE, bg="white", fg="grey", inches=F, squares=rep(1, n))
这有点痛苦。本质上,您是在自己实施 corrplot.mixed
,唯一的区别是您可以将单独的额外参数传递给上层和下层(corrplot.mixed
不能)。
从 corrplot
版本 0.84 开始,现在可以使用不同颜色的文本和省略号 here。例如,
corrplot.mixed(MyMatrix, lower.col = "black", number.cex = .7)
指定矩阵下半部分的文字为黑色。
在 r
包 corrplot
中,您可以在相关矩阵的下半部分和上半部分混合图形类型,以获得漂亮的视觉效果。我希望在矩阵的下半部分有数字,在矩阵的上半部分有省略号——这样就可以了。但是,根据我的数据,我看不到一些相关数字,因为它们接近 0。下面是我正在使用的代码和当前输出。
有没有办法改变矩阵下半部分的文本颜色?我想将相关系数的颜色更改为不是白色(它们不需要从红色变为蓝色,黑色也可以)。
#Saves the correlation matrix for reproducibility
#The matrix was modified based on the answer here:
cormatx <- structure(c(1, 0.480473436029381, 0.727971392165508, 0.0755790813842022,
0.647226624978262, 0.706156814758194, 0.73971915882987, 0.073024457099958,
0.480473436029381, 1, 0.540515552878261, 0.106196818240067, 0.505171500429873,
0.480694458288349, 0.538693541543583, 0.158300667842954, 0.727971392165508,
0.540515552878261, 1, 0.111168537597397, 0.587432598932939, 0.673406541830384,
0.724533755640279, 0.139232852746538, 0.0755790813842022, 0.106196818240067,
0.111168537597397, 1, -0.0844917222701804, 0.0382605955575862,
-0.00462812019681349, 0.000406894700952559, 0.647226624978262,
0.505171500429873, 0.587432598932939, -0.0844917222701804, 1,
0.668544141384562, 0.761303240927891, 0.152127182963817, 0.706156814758194,
0.480694458288349, 0.673406541830384, 0.0382605955575862, 0.668544141384562,
1, 0.772678948045676, 0.119611111043454, 0.73971915882987, 0.538693541543583,
0.724533755640279, -0.00462812019681349, 0.761303240927891, 0.772678948045676,
1, 0.174453831824302, 0.073024457099958, 0.158300667842954, 0.139232852746538,
0.000406894700952559, 0.152127182963817, 0.119611111043454, 0.174453831824302,
1), .Dim = c(8L, 8L), .Dimnames = list(c("A. SAT Critical Reading",
"B. SAT Mathematics", "C. SAT Writing Multiple Choice", "D. SAT Essay",
"E. TOEFL Listening Comprehension", "F. TOEFL Structure and Written Expression",
"G. TOEFL Reading Comprehension", "H. TOEFL Test of Written English"
), c("A", "B", "C", "D", "E", "F", "G", "H")))
#Creates the corrplot
corrplot.mixed(cormatx, upper = "ellipse", lower = "number",
tl.pos = "lt", tl.col = "black", tl.offset=1, tl.srt = 0)
他们在 ?corrplot
中有一个这样的例子(在 "circle + black number" 下)。看起来您必须调用 corrplot
两次:一次是先绘制椭圆(彩色),然后再次分别绘制系数(指定例如 colour=black),因为如果您在中指定 col="black"
corrplot.mixed
椭圆也是黑色的。
此外,如果您查看 corrplot.mixed
代码,您会发现它向 upper 和 lower 调用传递了相同的 ...
,这就是为什么指定例如colour="black"
到 corrplot.mixed
会将您的省略号和文本都绘制为黑色,而不仅仅是文本。
即
# draw ellipses + decorations
corrplot(cormatx, type="upper", method="ellipse",
tl.pos="lt", tl.col="black", tl.offset=1, tl.srt=0)
# draw labels in black (disabling all the other stuff already drawn)
corrplot(cormatx, add=T, type="lower", method="number",
col="black", diag=F, tl.pos="n", cl.pos="n")
# if you don't like the lines on the diagonal, (ie diag="n" of corrplot.mixed),
# having a look at corrplot.mixed yields the following code:
n <- nrow(cormatx)
symbols(1:n, n:1, add=TRUE, bg="white", fg="grey", inches=F, squares=rep(1, n))
这有点痛苦。本质上,您是在自己实施 corrplot.mixed
,唯一的区别是您可以将单独的额外参数传递给上层和下层(corrplot.mixed
不能)。
从 corrplot
版本 0.84 开始,现在可以使用不同颜色的文本和省略号 here。例如,
corrplot.mixed(MyMatrix, lower.col = "black", number.cex = .7)
指定矩阵下半部分的文字为黑色。