[R] Draw abbreviated key (lattice, xyplot)

Vaclav Petricek vaclav.petricek at mff.cuni.cz
Thu Mar 18 16:42:15 CET 2004


Hello

I have been experimenting with xyplot, reading the help and googling but
I am still unable to draw an abbreviated key.

I would like to display key for a few particular countries.

My dataset looks like this

   year papers        country papers.total
1  1988    403            USA          551
2  1988     31 United Kingdom          551
3  1988     24         Canada          551
4  1988     20    Netherlands          551
5  1988     19         Israel          551
6  1988     16        Germany          551
7  1988     13         France          551
8  1988     10          Italy          551
9  1988      8    Switzerland          551
10 1988      5          Japan          551
11 1988      5        Denmark          551
12 1988      3          Spain          551
13 1988      3         Russia          551
14 1988      2         Sweden          551
15 1988      2         Poland          551
16 1988      2        Finland          551
17 1988      2         Brasil          551
18 1988      2      Australia          551
19 1988      1       Thailand          551
20 1988      1         Norway          551
21 1988      1         Mexico          551
22 1988      1        Ireland          551
23 1988      1         Greece          551
24 1989    649            USA          926
25 1989     53 United Kingdom          926
26 1989     43         France          926
27 1989     37         Canada          926
28 1989     36        Germany          926
29 1989     28    Netherlands          926
30 1989     19         Sweden          926
[...]

I use xyplot to show how many papers

> xyplot(papers~year,groups=country,type='l',auto.key=T)

produces an extremely long key

> xyplot(papers~year,groups=country,type='l',key=simpleKey(levels(as.factor(country))[1:5]))

shows *alphabetically* first five countries in the key

> xyplot(papers~year,groups=country,type='l',key=simpleKey(c('USA','Germany')))

displays correct countries but the colors obviously do not match.

Could you please point me in the right direction?

Vaclav




More information about the R-help mailing list