Skip to content

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

5 messages · David Winsemius, Frostygoat, Phil Spector

#
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.
#
On Nov 29, 2009, at 9:30 PM, Frostygoat wrote:

            
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.
#
Thanks for the suggestion David. With mapply the lines are correctly
plotted but they are all red, the points are colored, but along the x
axis, not along the individual lines.
#
One of the reasons we ask for a *reproducible* example, is that
it allows us to test our ideas and make sure that all the details
are taken care of.  Here's a reproducible example that may help
solve your problem:

lx100=c(1,1,1,.8,.5,.4,.2,0)
day100=c(0,1,2,3,4,5,6,7)
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)
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)

lx = list(lx0=lx0,lx90=lx90,lx100=lx100)
day = list(day0=day0,day90=day90,day100=day100)

plot(range(unlist(day)),range(unlist(lx)), type="n", xlab="Day of adult life",ylab='lx',lwd=2.2)

mapply(function(x,y,col)points(x,y,type='b',col=col),day,lx,rainbow(length(lx)))
legend('topright',names(lx),pch=1,lty=1,col=rainbow(length(lx)))
title('Survival vs. Time')

 					- Phil Spector
 					 Statistical Computing Facility
 					 Department of Statistics
 					 UC Berkeley
 					 spector at stat.berkeley.edu
On Sun, 29 Nov 2009, Frostygoat wrote:

            
#
It was arbitrary data and I made a mistake.  Thanks for your help
nonetheless.
I solved the problem using matpoints, which does the job quite nicely:

        
On Nov 30, 10:27?am, Phil Spector <spec... at stat.berkeley.edu> wrote: