[R] add a color band

Alaios alaios at yahoo.com
Sat Oct 26 23:39:11 CEST 2013


Hi Jim and thanks for your answer... I might be too tired with my new born or just exhausted.

I am attaching for everyone a small data snipset that you can load


load("DataToPlotAsImage.Rdata")
require(plotrix)
browser()
test<-data
# 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,ncol(test),length.out=10),labels=seq(201,300,length.out=10))
color.legend(104,30,112,70,seq(-110,-30,length=11),
  align="rb",rect.col=color.scale(1:30,1,c(0,1),0),gradient="y")

as you can see I have problems where the legend appears. My par("usr"  returned me
par("usr")
# [1]   0 351   0 200

but I am not sure how to read that to place the legend at a useful place. 
second I am not sure why the image is so full with black rows..

What I want is to have the legend visible
and later on customize the x axis to write custom string of different size... First I need though to fix the more severe problems as I have described

Regards
Alex




On Friday, October 25, 2013 11:45 PM, Jim Lemon <jim at bitwrit.com.au> wrote:
 
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


More information about the R-help mailing list