Skip to content
Prev 293404 / 398503 Next

Simple plot loop

On 05/03/2012 05:50 PM, Ben Neal wrote:
Hi Ben,
I think what you may want in your loop is this:

for(column in names(Data2)[2:length(Data2)])
  lines(MONTH,column,type="o",pch=22,lty=2,col="blue")

But, if you want the first two lines to be green, you'll probably have 
to get a vector of colors:

colorvec<-rep("blue",length(Data2))
colorvec[1]<-"red"
colorvec[2:3]<-"green"

and change the above to:

columnnames<-names(Data2)
for(column in 2:length(Data2))
  lines(MONTH,columnnames[column],type="o",pch=22,lty=2,col=colvec[column])

Jim