[R] lines through points in lattice legend

Deepayan Sarkar deep@y@n@@@rk@r @end|ng |rom gm@||@com
Sat Jan 28 16:46:55 CET 2023


On Sat, Jan 28, 2023 at 2:49 PM Kenneth Knoblauch
<ken.knoblauch using inserm.fr> wrote:
>
> Hi,
>
> I'm struggling to find if there is a simple way to make the lines and points overlap in a legend for a lattice plot using auto.key.  Here is a toy example of what doesn't work (for me) as the lines and points are adjacent rather than overlapping:
>
> library(lattice)
> d <- data.frame(x = 1:2, y = 1:4, f = factor(letters[1:2]))
>
> xyplot(y ~ x, d, groups = f, type = "b",
>         pch = 21:22, fill = c("white", "black"), col = "black",
>         par.settings = list(superpose.symbol =
>         list(pch = 21:22, fill = c("white", "black"), col = "black"),
>         superpose.line = list(col = "black")),
>         auto.key = list(space = "right", points = TRUE, lines = TRUE))

Just adding a type = "b" should work (for the lines), so something like:

       auto.key = list(space = "right", type = "b",
                       points = FALSE, lines = TRUE)

BTW, once you specify par.settings, you don't need to specify the
parameters again, so you can drop the second line.

Best,
-Deepayan

>
>
> I've seen a few examples on stack.overflow but I haven't been able to make them work, or they seem more complicated then I would think it should be (but I don't exclude that I'm fooling myself there).
>
> R version 4.2.2 Patched (2023-01-04 r83564)
> Platform: x86_64-apple-darwin17.0 (64-bit)
> Running under: macOS Catalina 10.15.7
>
> Matrix products: default
> BLAS:   /Library/Frameworks/R.framework/Versions/4.2/Resources/lib/libRblas.0.dylib
> LAPACK: /Library/Frameworks/R.framework/Versions/4.2/Resources/lib/libRlapack.dylib
>
> locale:
> [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
>
> attached base packages:
> [1] stats     graphics  grDevices utils     datasets  methods   base
>
> other attached packages:
> [1] lattice_0.20-45
>
> loaded via a namespace (and not attached):
> [1] compiler_4.2.2 grid_4.2.2
>
>  Thanks for any enlightenment, in advance.
>
> Ken
>
>   ___
>   Kenneth Knoblauch
>  Inserm U1208
>  Stem-cell and Brain Research Institute
>  18 avenue du Doyen Lépine
>  69500 Bron
>  France
>  tel: +33 (0)4 72 91 34 77
>  fax: +33 (0)4 72 91 34 61
>  portable: +33 (0)6 84 10 64 10
>  https://sbri.fr/public-profile/63/single-member/
>
> ______________________________________________
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.



More information about the R-help mailing list