[R] Plot legend

Sherri Heck sheck at ucar.edu
Sat Apr 11 00:59:55 CEST 2009


Dear All-

I am trying to create a legend where the first 9 terms are represented as pch=16 in one column (which I am able to do); but, I would like the last two terms in that column to be 'lines" (which are black and red - just as it looks like in the plot).  I have read through many help pages and searched the help listserv, but haven't figured this one out yet.  Does anyone have any suggestions or if you could point me to a help page that i may have missed, I would greatly appreciate it. a bit of my code is below:

thanks-

sherri



plot(CO2ppm_1$CO2_ppm,ylim=c(-7,10),
axes = FALSE,type="b",pch=16,cex=1,col="skyblue4",main="TC (Model AM2t) SPL Mean Diurnal Cycle",xlab="Hours (GMT)",ylab="CO2(ppm)",col.main="black",font.main=4,lwd=1.8,col.lab="black",col.sub="Black")

points(CO2ppm_2$CO2_ppm,type="b",pch=16,col="green")
points(CO2ppm_3$CO2_ppm,type="b",pch=16,col="dark orange")
points(CO2ppm_4$CO2_ppm,type="b",pch=16,col="light green")
points(CO2ppm_5$CO2_ppm,type="b",pch=16,col="dark green")
points(CO2ppm_6$CO2_ppm,type="b",pch=16,col="yellow")
points(CO2ppm_7$CO2_ppm,type="b",pch=16,col="dark blue")
points(CO2ppm_8$CO2_ppm,type="b",pch=16,col="purple")
points(CO2ppm_9$CO2_ppm,type="b",pch=16,col="dark red")
lines(sub_dlyavg_w[,1],type="l",lwd=3,col="black")
lines(sub_dlyavg_p[,1],type="l",lwd=3,col="red")


axis(1, at=1:23, labels=as.character(seq(1,23)), cex.axis=.7)
axis(2, at=-7:10, labels=as.character(seq(-7,10)), cex.axis=.7)
box(col = 'black')
mtext("June - August", font=2,side=3,cex=1,col="black")

legend("topright",c('Level 1','Level 2','Level 3', 'Level 4','Level 5',
'Level 6','Level 7','Level 8','Level 9','RAC UNFILT','RAC FILT 1 sig'),lty=1,pch=c(16,16,16,16,16,16,16,16,16),col=c('skyblue4','green','orange',
'light green','dark green','yellow','dark blue','purple','dark red','black', 'red'),ncol=1)

legend("bottomleft",c('Model:          2002-2003','RACCOON: 2005-2008'), 
cex = 1,col = c('black'),ncol=1)




More information about the R-help mailing list