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

Frostygoat frostygoat at gmail.com
Mon Nov 30 03:30:16 CET 2009


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")

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.




More information about the R-help mailing list