Hello, I'm running into a frustrating problem with the legend on a lattice plot I'm working with. The plot is a stripplot with a panel.linejoin () line running through the mean of each of the categories. Thus there are both points and lines in the plot. In trying to make a key for the plot, I can't figure out how to make a legend for both the points and the lines. What I'd like is something like: prices * means ----- in which there are two "rows" in the legend, one with the point and its label and one with the line and its label. By supplying this type of argument to stripplot: key=list(text=list(lab="prices"), points=list(...), text=list(lab="means"), lines=list(...)) I can get a legend that looks like: prices * means ----- But this looks awkward with my plot Is there any way to have the plot elements and their labels be in the same column? Thanks, Peter
Sundar Dorai-Raj
2007-Mar-20 22:53 UTC
[R] lattice key (legend) with both points and lines
Peter McMahan said the following on 3/20/2007 3:16 PM:> Hello, > I'm running into a frustrating problem with the legend on a lattice > plot I'm working with. The plot is a stripplot with a panel.linejoin > () line running through the mean of each of the categories. Thus > there are both points and lines in the plot. > In trying to make a key for the plot, I can't figure out how to make > a legend for both the points and the lines. What I'd like is > something like: > > prices * > means ----- > > in which there are two "rows" in the legend, one with the point and > its label and one with the line and its label. By supplying this type > of argument to stripplot: > > key=list(text=list(lab="prices"), > points=list(...), > text=list(lab="means"), > lines=list(...)) > > I can get a legend that looks like: > > prices * means ----- > > But this looks awkward with my plot > > Is there any way to have the plot elements and their labels be in the > same column? > > Thanks, > Peter > > ______________________________________________ > R-help at stat.math.ethz.ch 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.You can try: library(lattice) xyplot(1:10 ~ 1:10, key = list(text = list(c("prices", "means")), lines = list( pch = c("*", ""), type = c("p", "l"), cex = 2, col = "red", lwd = 3))) HTH, --sundar