# [R] Rectangle height in lattice xyplot key

Deepayan Sarkar deepayan.sarkar at gmail.com
Tue Jan 11 08:14:41 CET 2011

```On Sun, Jan 9, 2011 at 9:31 AM, Duncan Mackay <mackay at northnet.com.au> wrote:
> Dear All
>
> I have a problem with the height of the boxes in the key in the following.
> (The text is over 2 lines to  accentuate the problem of no space between the
> rectangles.)
> Is there an easy way to put a space between the rectangles; size controls
> the width but there appears to be nothing for the height?

There is now (in the last update of lattice, released last week). So
the following should work:

xyplot(1~1,
key = list(corner = c(0.8,0.8),
cex   = 0.6,
title = "Functional Groups",
cex.title = 0.7,
columns = 1,
text  = list(label =
c("Tree","Shrub\n(low)","Herb","Grass","Shrub\n(small)")),
points = list(pch = c(1,3,4,20,16),
col = c(2,3,4,5,6)),
lines = list(col = c(2,3,4,5,6),
size = 2),
rectangles = list(col = c(2,3,4,5,6),
size = 1,
height = 0.7, ## newly added
border = FALSE)) )

Of course 'height' is just a multiplier, so the heights are still not
all the same because of differing row heights, but I assume that's not
going to be a problem in your real example.

-Deepayan

>
>        xyplot(1~1,
>           key = list(corner = c(0.8,0.8),
>                      cex   = 0.6,
>                      title = "Functional Groups",
>                      cex.title = 0.7,
>                      columns = 1,
>                      text  = list(label =
> c("Tree","Shrub\n(low)","Herb","Grass","Shrub\n(small)")),
>                      points = list(pch = c(1,3,4,20,16),
>                                    col = c(2,3,4,5,6)),
>                      lines = list(col = c(2,3,4,5,6),
>                                      size = 2),),
>                      rectangles = list(col = c(2,3,4,5,6),
>                                        size = 1,
>                                        border = FALSE)) )
>
> I could get things to work when the legend was on top using
>  http://finzi.psych.upenn.edu/R/Rhelp02/archive/46654.html on something
> similar
> but could not get it to work in the last panel of a multipanel plot.
>
> Regards
>
> Duncan Mackay
> Department of Agronomy and Soil Science
> University of New England
> Armidale NSW 2351
> Email: home mackay at northnet.com.au
>
> R version 2.12.1 (2010-12-16)
> Platform: i386-pc-mingw32/i386 (32-bit)
>
> locale:
> [1] LC_COLLATE=English_Australia.1252  LC_CTYPE=English_Australia.1252
> LC_MONETARY=English_Australia.1252
> [4] LC_NUMERIC=C                       LC_TIME=English_Australia.1252
>
> attached base packages:
> [1] splines   datasets  utils     stats     graphics  grDevices grid
>  methods   base
>
> other attached packages:
>  [1] locfit_1.5-6        akima_0.5-4         lme4_0.999375-37
> Matrix_0.999375-46  mgcv_1.7-2
>  [6] geepack_1.0-17      doBy_4.1.2          contrast_0.13 Design_2.3-0
>    Hmisc_3.8-3
> [11] survival_2.36-2     gee_4.13-16         R2HTML_2.2          zoo_1.6-4
>         gsubfn_0.5-5
> [16] proto_0.3-8         RODBC_1.3-2         gtools_2.6.2 xtable_1.5-6
>  R.oo_1.7.4
> [21] R.methodsS3_1.2.1   foreign_0.8-41      chron_2.3-39 MASS_7.3-9
>  latticeExtra_0.6-14
> [26] RColorBrewer_1.0-2  lattice_0.19-13
>
> loaded via a namespace (and not attached):
> [1] cluster_1.13.2 nlme_3.1-97    stats4_2.12.1  tools_2.12.1
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help