I may have misunderstood but if you just want the text labels rotated, you can do so by changing the source of cor.plot
, specifically the line text(rx, ry, round(r * 100))
to text(rx, ry, round(r * 100), srt=45)
, giving something like this:
Displaying the numbers in an R correlation matrix diagonally
Вопрос
I am generating a correlation matrix using
library(psych)
corMat = cor(data)
cor.plot(corMat,numbers=TRUE,colors=TRUE,n=51,main=NULL,labels=NULL)
but want to alter it so that the numbers displayed inside the heatmap are displayed diagonally.
Решение
Другие советы
Doesn't look like cor.plot
can pass any arguments through to the text
call that plots the numbers. So, you can modify the function but opening the source (edit(cor.plot)
) and changing the line
text(rx, ry, round(r * 100))
to
text(rx, ry, round(r * 100), srt = 45)
or however many degrees you want to rotate the numbers by. Then you can copy that code and define a new function (my.cor.plot
) with the modified code.
I think that there's less hack-ish ways of doing this, but I've never used them and this will work.
That is a great suggestion and is now implemented in psych version 1.3.10.11 (to be released today to Cran). This is done by adding ... to the text command. Specifically,
text(rx,ry,round(r*100),...)
This has the advantage of making use of the power of the graphic parameters.
As of today you can now specify cor.plot(correlation.matrix, numbers=TRUE,srt=45).
Thanks.
Bill