本文介绍了在corrplot.mixed中更改文本颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

rcorrplot中,您可以在相关矩阵的下半部和上半部混合图形类型,以提供良好的视觉效果.我想在矩阵的下半部分有数字,在矩阵的上半部分有椭圆形-很好.但是,根据我的数据,我看不到一些相关数字,因为它们接近0.下面是我正在使用的代码和当前输出.

In the r package corrplot, you can mix the type of figure on the lower and upper half of a correlation matrix to make a nice visual. I would like to have numbers on the lower half of my matrix, and ellipses on the top half of the matrix - that is all fine. But, with my data I cannot see some of the correlation numbers since they are near 0. Below is the code I am using and current output.

是否可以更改矩阵下半部分的文本颜色?我想将相关系数的颜色更改为不为白色(它们不必从红色变为蓝色,也可以使用黑色).

Is there a way to change the text color for the lower half of the matrix? I'd like to change the colors of the correlation coefficients to not be white (they don't need to be red to blue, black would be ok).

#Saves the correlation matrix for reproducibility
#The matrix was modified based on the answer here: http://stackoverflow.com/a/36893890/5623577
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中的示例(在圆圈+黑色数字"下).看来您必须调用corrplot两次:一次先绘制椭圆(用彩色),然后再分别绘制系数(指定例如colour = black),因为如果在corrplot.mixed中指定col="black"椭圆也将是黑色的.

They have an example of this buried in ?corrplot (it's under "circle + black number"). It looks like you have to call corrplot twice: once to draw the ellipses first (in colour) and then again to draw the coefficients (specifying e.g. colour=black) separately, because if you specify col="black" in corrplot.mixed the ellipses will also be black.

此外,如果您查看corrplot.mixed代码,则可以看到它将相同的...传递给上下调用,这就是为什么指定例如colour="black"转换为corrplot.mixed会将椭圆和文本绘制成黑色,而不仅仅是文本.

Also if you look at corrplot.mixed code, you can see it passes the same ... to both the upper and lower calls, which is why specifying e.g. colour="black" into corrplot.mixed will draw both your ellipses and text black rather than just the text.

# 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不能这样做).

It's a bit of a pain. Essentially you are implementing corrplot.mixed yourself, the only difference being that you can pass separate extra arguments to the upper and the lower (which corrplot.mixed can't).

这篇关于在corrplot.mixed中更改文本颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 21:00