I wanted to make a legend that had both points and lines. I wasn't sure how hard that would be (maybe there would be two legends, who knew!). A quick google search turned up quick and simple ways to do this.
You already need to have made a plot to do this. But once you have your plot, this code works.
legend( x="topright", #places it in the top right; see help via ?legend for other options.
bty="n", #no box around legend
cex=0.9, #slightly smaller than the actual plot symbols and text
legend=c(expression("Critical" ~ chi^2), #Fancy symbols and superscripts in this one!
"Pointy points",
"Gray line",
"Round points"), #Legend specifies what text shows.
col=c("black","black",
"gray","black"), #Colors for each symbol.
lwd=2, #Line widths and border widths for both points and lines.
lty=c(1,NA,1,NA), #The line types for each line.
pch=c(NA,5,NA,1), #The symbols for each point
merge=FALSE ) #does NOT merge points and lines.
No comments:
Post a Comment
Comments and suggestions welcome.