[R] help with legend()

Deepayan Sarkar deepayan at stat.wisc.edu
Fri Oct 17 16:04:33 CEST 2003


On Friday 17 October 2003 02:20, Martin Maechler wrote:
> >>>>> "PaulSch" == Schwarz, Paul <paul.schwarz at oregonstate.edu>
> >>>>>     on Wed, 15 Oct 2003 12:09:11 -0700 writes:
>
>     PaulSch> I am converting some S-PLUS scripts that I use for
>     PaulSch> creating manuscript figures to R so that I can take
>     PaulSch> advantage of the plotmath capabilities.  In my
>     PaulSch> S-PLUS scripts I like to use the key() function for
>     PaulSch> adding legends to plots,
>
> AFAIK  key() in S+ is from the trellis library section.
> The corresponding R package, trellis, has
                               ^^^^^^^
lattice, actually :-)

> a draw.key() function that may work similarly to S-plus' key()
> {Deepayan ?}.

That's correct. Of course, the S-PLUS key() works wih non-trellis graphs as 
well, whereas draw.key() will produce a grid object and hence work with grid 
graphics only. (I haven't checked Paul's new gridBase package, that may 
enable using this for base graphics as well.)

>     PaulSch> and I have a couple of
>     PaulSch> questions regarding using the legend() function in
>     PaulSch> R.
>
>     PaulSch> 1) is there a way to specify different colors for
>     PaulSch> the legend vector of text values?
>
> not yet in legend() -- but see below
>
>     PaulSch> 2) is there a way to reverse the order of the
>     PaulSch> legend items so that the text values precede the
>     PaulSch> symbols?
>
> not yet in legend()   --- but it's an open source project living
> 		       from "community support" ...
>
> Can S+ key() do these two things?
> If yes, how do you specify it there
> {this sounds as if I was willing to consider adding these wished
>  features to legend .... }

key() is a bit weird, in that it allows multiple arguments of the same name 
(as long as the names are text, points, lines and rectangles). The order of 
the arguments control the order of column types.

For example, 

key(text = list(letters[1:5], col = 1:5), 
    points = list(col = 1:5),
    text = list(letters[6:10]))

will produce a column of text followed by points and then text again (with the 
first two columns in different color).

Deepayan




More information about the R-help mailing list