On Wed, 4 Jan 2017, Artur Tarassow wrote:
Thank, Allin! It works fine now! Of course the triangle is just an
option
which I personally prefer. No need to run lower() before.
Btw, do you think this could become a public package similar to the (of
course) much more sophisticated R-package corrplot (URL:
https://cran.r-project.org/web/packages/corrplot/vignettes/corrplot-intro...
I agree this is a nice thing to have, and in fact I'm considering
adding it as built-in functionality. However, if that takes too long
then we can take the function-package direction.
To compare notes, here's my version of correlation plot (drawing
heavily on yours, of course). One point to notice is that if you give
gnuplot a matrix as inline input, it seems you're supposed to
terminate the input with two "e" lines. It's like that in the gnuplot
help file, and if there are any further commands after the matrix data
gnuplot throws an error when there's only one "e".
<hansl>
set echo off
set messages off
function void corrplot (matrix M, strings vnames, string fname)
M = mreverse(M)
scalar n = rows(M)
string tmpname = "(a)dotdir/corrplot.gp"
string sfx
outfile @tmpname --write
printf "set nokey\n"
printf "set tics nomirror\n"
printf "set cbrange [-1:1]\n"
printf "set palette defined (-1 'blue', 0 'white', 1
'red')\n"
# y-axis tics
printf "set ytics ("
loop i=1..n -q
sfx = i < n ? ", " : ""
printf "\"%s\" %d%s", vnames[i], n-i, sfx
endloop
printf ") out\n"
# x-axis tics
printf "set xtics ("
loop i=1..n -q
sfx = i < n ? ", " : ""
printf "\"%s\" %d%s", vnames[i], i-1, sfx
endloop
printf ") out\n"
printf "set xtics rotate by 45 right\n"
# matrix/image plot
printf "plot '-' matrix with image\n"
loop i=1..n -q
loop j=1..n -q
printf "%.4f ", M[i,j]
endloop
printf "\n"
endloop
printf "e\ne\n"
outfile --close
gnuplot --input="@tmpname" --output="@fname"
remove(tmpname)
end function
open data4-10
list X = dataset
corr X
corrplot(mcorr({X}), varnames(X), "display")
</hansl>
Allin