Hi: It would really help to have a reproducible example to see exactly what problems you're having, but here's a simple manufactured example to illustrate how to produce a basic legend. The plot below is one with three different 'y' variables against the same x. The x and y limits are made wide enough to contain all the data with room for a legend.
# Fake data: dd <- data.frame(x = 1:20, y1 = rnorm(20, 2, 1), y2 = rnorm(20, 4, 1), y3 = rnorm(20, 6, 1)) summary(dd) # check the ranges of the y-variables first plot(y1 ~ x, data = dd, type = 'l', xlim = c(0, 25), ylim = c(-1, 10)) lines(y2 ~ x, data = dd, lty = 'dotted') lines(y3 ~ x, data = dd, lty = 'dashed') lnames <- c('y1', 'y2', 'y3') legend('topright', legend = lnames, lty = c('solid', 'dotted', 'dashed')) If you want to increase the thickness of the legend lines to improve visibility, use lwd, as in legend('topleft', legend = lnames, lty = c('solid', 'dotted', 'dashed'), lty = 2) HTH, Dennis On Wed, Jul 21, 2010 at 9:06 PM, li li <hannah....@gmail.com> wrote: > Hi all, > I am have some difficulty with the legend function. > I need to add a legend to describe the different line types in a plot. The > legend box is small. > It did not include sufficient length of each line type to help distinguish > the differnt line types. > Is there a way to fix this. > Thank you > Hannah > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help@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. > [[alternative HTML version deleted]] ______________________________________________ R-help@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.