簡體   English   中英

更改corrplot.mixed中的文本顏色

[英]Change text color in corrplot.mixed

rcorrplot ,您可以在相關矩陣的下半部分和上半部分混合圖形類型以形成良好的視覺效果。 我想在矩陣的下半部分有數字,在矩陣的上半部分有橢圓 - 這一切都很好。 但是,根據我的數據,我無法看到一些相關數字,因為它們接近0.下面是我正在使用的代碼和當前輸出。

有沒有辦法改變矩陣下半部分的文字顏色? 我想將相關系數的顏色改為不是白色(它們不需要是紅色到藍色,黑色就可以了)。

#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 :一次先繪制橢圓(彩色),然后再分別繪制系數(指定顏色=黑色),因為如果你在corrplot.mixed指定col="black" 。橢圓也是黑色的。

此外,如果你看一下corrplot.mixed代碼,你可以看到它傳遞相同的...同時上下調用,這就是為什么在corrplot.mixed指定例如colour="black"將繪制你的省略號和文本黑色而不僅僅是文本。

# 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開始,現在可以有不同的顏色文本和省略號,如此處所述 例如,

corrplot.mixed(MyMatrix, lower.col = "black", number.cex = .7)

指定矩陣下半部分的文本為黑色。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM