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)
Plot legend
3 messages · Sherri Heck, Jim Lemon, PIKAL Petr
Sherri Heck wrote:
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:
Hi Sherri,
A really quick hack is to use the hyphen for the lines:
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'),
pch=c(16,16,16,16,16,16,16,16,16,45,45),
col=c('skyblue4','green','orange','light green','dark green','yellow',
'dark blue','purple','dark red','black','red'),ncol=1)
Jim
2 days later
Hi When I tried to make a plot according to your code I got
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") Error in plot(CO2ppm_1$CO2_ppm, ylim = c(-7, 10), axes = FALSE, type = "b", : object 'CO2ppm_1' not found so it can be that you use some data I do not have available. Anyvey you can vectorize your specification of legend like that
plot(1,1)
legend("topright", legend=letters[1:3], pch=c(19,19,NA), lty=c(NA,1,2))
and use NA when you do not want this symbol plotted. Regards Petr r-help-bounces at r-project.org napsal dne 11.04.2009 00:59:55:
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)
______________________________________________ R-help at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.