On 10/25/2013 11:16 PM, Alaios wrote:
Hi Jim and thanks for help

I will need some help to make
-the legend visible (probably at the right side of the window)
-split the legend at 0.1 steps -1,-0.9,-0.8.....1 and
-assign a color heat.color(30). I have selected orange and reds
-show me the way to change the size of legend if it would be needed



par(mar=c(7,4,4,6))
test<-matrix(data=runif(10000),nrow=100)
color2D.matplot(test,axes="F",xlab="",ylab="",show.legend=FALSE)
#,show.legend=TRUE
axis(1,at=seq(1:nrow(test)),labels=seq(201,300)) #
color.legend(11,6,11.8,9,seq(-1,1,length=10),rect.col=heat.colors(30),gradient="y")

Hi Alex,
You can do this in at least two ways. The first example uses the color.scale function to assign colors close to those of heat.colors. The second shows how to use heat.colors if you want that.

library(plotrix)
par(mar=c(7,4,4,6))
test<-matrix(data=runif(10000),nrow=100)
# this transforms the values of "test" into red->yellow
color2D.matplot(test,axes="F",xlab="",ylab="",main="color.scale",
 extremes=c("#FF0000","#FFFF00"),show.legend=FALSE)
axis(1,at=seq(1:nrow(test)),labels=seq(201,300))
# use par("usr") to find out the plot dimensions,
# then place the legend where you want it
color.legend(104,30,112,70,seq(-1,1,length=11),
 align="rb",rect.col=color.scale(1:30,1,c(0,1),0),gradient="y")
# now try it with heat.colors
test.cut<-matrix(as.numeric(cut(test,breaks=seq(0,1,length.out=30))),nrow=100)
color2D.matplot(test.cut,axes="F",xlab="",ylab="",main="heat.colors",
 cellcolors=heat.colors(30)[test.cut],show.legend=FALSE)
axis(1,at=seq(1:nrow(test)),labels=seq(201,300))
color.legend(104,30,112,70,seq(-1,1,length=11),
 align="rb",rect.col=heat.colors(30),gradient="y")

Jim

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to