Skip to content
Prev 202166 / 398506 Next

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

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: