[R] both lines and plot characters in a lattice plot key
deepayan.sarkar at gmail.com
Tue Dec 25 22:45:39 CET 2007
On 12/25/07, Hofert Marius <m_hofert at web.de> wrote:
> I have two short questions concerning a key (legend) in a lattice
> plot. I have points represented by two different plot characters
> (crosses and circles) and they are colored from light to dark gray. I
> would like to have 3 parts in my legend showing the two different
> plot characters in the first two lines and the last line should
> consist of a line segment for explaining the different shades of
> gray. Below you can see what I reached so far.
> My first problem is, that I do not get the 2 plot characters and the
> line segment vertically aligned to each other (I chose the vector of
> plotting characters to contain "26" as last element, because this
> leaves out a plotting character for the last line, where the line
> segment should be placed). So how do I get these aligned?
The 'lines' components allow a 'type' specification, so:
lines=list(pch=c(1,3,1), type = c("p", "p", "l")),
text=list(c("key 1","key 2","key 3")),
> My second question is, if it's possible to have a line segment shown
> in the key, which is colored from light to dark gray (instead of a
> single color), matching the colors in my specified variable "colors"
> if possible, i.e. a single line segment starting from light gray and
> ending with a dark gray.
Unfortunately, no, at least not using the 'key' argument. However,
using the 'legend' argument gives you more flexibility, especially if
you are willing to write some grid code. Even without grid, you can
use draw.key() and draw.colorkey() together to produce one legend for
the plotting characters and a different one for the color gradient.
> Thanks very much in advance!
> (1,3,26)),text=list(c("key 1","key 2","key 3")),align=T,transparent=T))
> R-help at r-project.org mailing list
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help