2016-11-01 50 views
1

パッケージcorrplotでは、相関行列の下半分と上半分に図形のタイプを混在させて、素敵なビジュアルにすることができます。私は行列の下半分に数値を、行列の上半分に楕円を付けることを望みます - それはすべて問題ありません。しかし、私のデータでは、相関係数が0に近いため、相関係数の数値は表示されません。以下は、私が使用しているコードと現在の出力です。corrplot.mixedのテキストの色を変更する

マトリックスの下半分のテキストの色を変更する方法はありますか?私は、相関係数の色を白くしないように変更したいと思っています(青から赤、黒は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) 

enter image description here

答えて

5

彼らは(それが "円+黒数" の下'S)?corrplotに埋め込まれたこの例を有します。 corrplotを2回呼び出す必要があります。つまり、corrplot.mixedcol="black"と指定すると、楕円も黒色になるため、楕円を最初に(色で)描画し、再び係数を描画するようにします(例:color = black)。

また、corrplot.mixedコードを見ると、それは同じ...を上位呼び出しと下位呼び出しの両方に渡すことがわかります。 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できません)。

2

corrplotバージョン0.84から、hereと異なる色のテキストと楕円を使用できるようになりました。例えば、

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

は、マトリックスの下半分のテキストが黒であることを指定します。

関連する問題