Skip to content
Prev 309867 / 398506 Next

lines with colored segments

On 11/05/2012 12:29 AM, David Stevens wrote:
Hi David,
Try this:

library(plotrix)
x<-c(0,cumsum(rnorm(99)))
y<-c(0,cumsum(rnorm(99)))
xydist<-sqrt(x*x+y*y)
plot(x,y,main="Random walk plot",xlab="X",ylab="Y",type="n")
color.scale.lines(x,y,col=2+(diff(xydist)>0))
boxed.labels(x,y,labels=1:100,border=FALSE,cex=0.5)

This colors a random walk with green if the "step" advances away from 
the start and red if it regresses toward the start. Just pass your 
colors in the "col=" argument.

Jim