[R] Assign palette (e.g. rainbow) to a series of points on 1 plot

David Winsemius dwinsemius at comcast.net
Mon Nov 30 04:09:42 CET 2009


On Nov 29, 2009, at 9:30 PM, Frostygoat wrote:

> I have 11 vectors representing insect survival probabilities in
> response to different levels of toxins at 10 concentrations
>
> lx100=c(1,1,1,.8,.5,.4,.2,0)
> day100=c(0,1,2,3,4,5,6,7,8)
>
> lx90=c(1,1,1,1,.9,.8,.6,.4,.2,.1,0)
> day90=c(0,1,2,3,4,5,6,7,8,9,10)
>
> #...and so on10% and a zero (control) series
>
> lx0=c(1,1,1,1,1,1,.9,.9,.8,.8,.6,.5,.4,.3,.2,.1,.1,0)
> day0=c(0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17)
>
> I want to plot them on one plot with a palette color scheme such as
> rainbow or topo.colors, and I want one color per concentration on both
> the point and line.  I have found a number of ways to plot them:
>
> 1. Plot a blank frame big enough to accommodate the control data and
> then add the x,y coords using points.
>
> plot(x=day0,y=lx0, type="n", xlab="Day of adult
> life",ylab=lx,lwd=2.2,ylim=c(0.0,1),col=cols)
> points(x=day100,y=lx100,type="b",col="#FF8B00")
> points(x=day90,y=lx90,type="b",col= "#E8FF00")
> ...
>
> This is harder than it should be, I tracked down the color names
> generated with rainbow(11) and individually name each points command.
>
> 2.  Bind the respective x and y coords into 2 respective matrices and
> plot.
>
> lxs=matrix(c(lx100,lx90,lx80,lx70,lx60...))
> days=matrix(c(day100,day90,day80,day70,day60...))
>
> plot(x=days,y=lxs, col=rainbow(11), type="b")

You have vectors of unequal length which may cause some problems. Have  
you thought of using plot with xlim and ylim and just one series and  
then following that with something like:

 > mapply(lines, days, lxs, MoreArgs=list(col=rainbow(3), type="b"))

It seemed to give somewhat sensible results using the series tha tyou  
offered even without the pre-determined x limits.

>
> The points rainbow (not as series) and the lines are red.
>
> I tried various methods of binding data and plotting data frames
> without success.

>
> I would appreciate it if someone would kindly put me on the trail.
> Thank you for your time.
>
-- 

David Winsemius, MD
Heritage Laboratories
West Hartford, CT




More information about the R-help mailing list