color2D.matplot Legend in R
Does anyone know how to change the placement of the legend in color2D.matplot (plotrix)? I have a12 x 12 correlation matrix. I noticed I had to reverse the row names and change 开发者_开发百科the margin to get the long names to fit. But now I am stumped on how to move the legend (without increasing the margin even more and making the graph look odd with so much white space at the bottom. Thanks!
cors<-cor(train)cellcol<-color.scale(cbind(cors,c(-1,rep(1,11))),c(0,1),0,c(1,0))[,1:12]
par(mar = c(10,8,4,2) + 0.1)
color2D.matplot(cors,cellcolors=cellcol,show.legend=TRUE,show.values=2,
axes=FALSE, xlab="",ylab="")
axis(1,at=0.5:11.5,las=2,labels=colnames(cors))
axis(2,at=0.5:11.5,las=2,labels=rev(rownames(cors)))
The help page says: "If the default is not suitable, call color.legend separately." And then gives an example.
Based on a guess (in the absence of any information about "train" or "cors", you can try:
color.legend(0,13,6.5,14,legend=c(-1,-0.5,0,0.5,1),
rect.col=color.scale(cbind(cors,c(-1,rep(1,11))),c(0,1),0,c(1,0))[,1:12],
align="rb")
精彩评论