[R] lattice: Synchronizing key and lines; or: why is lty used as lwd in legend?
Deepayan Sarkar
deepayan.sarkar at gmail.com
Tue Feb 8 10:51:08 CET 2011
On Mon, Feb 7, 2011 at 1:10 PM, Dieter Menne
<dieter.menne at menne-biomed.de> wrote:
> Dear latticists,
>
> Getting legend and graph line types synchronized has been a challenge in
> lattice; the last example below that works looks ridiculously ugly for such
> a simple job, I am sure there is a more elegant solution.
>
> When trying this out, I found a feature which I found confusing: why are
> line types (lty) "translated" to line widths (lwd) in the legend? See
> attached pdf in case this should not be reproducible on your computer.
This looks like a bug newly introduced in the recent lattice update,
your examples work as expected in earlier versions.
I will look into it. In the meantime, going back to version 0.19-13 may help.
-Deepayan
> Dieter
>
>
> Library(lattice)
> os = OrchardSprays[OrchardSprays$rowpos <4,]
> os$rowpos = as.factor(os$rowpos)
>
> # Set it globally
> # This is confusing: why is lty used as lwd in legend??
> trellis.par.set(superpose.line = list(col=c("blue","red","green"),
> lwd = 2, lty=c(1,4,6)))
> xyplot(decrease ~ treatment, os, groups = rowpos,
> type = "a", auto.key =
> list(space = "right", points = FALSE, lines = TRUE))
> dev.off()
>
> # To me, this seems to be the most consistent method if it worked.
> s= simpleTheme(lty=c(1,4,6),col=c("red","blue","green"),lwd=3)
> xyplot(decrease ~ treatment, os, groups = rowpos,
> par.settings=s,
> type = "a", auto.key =
> list(space = "right", points = FALSE, lines = TRUE))
>
> # !!! There must be an easier way to synchronize legend and plot
> xyplot(decrease~treatment,data=os,groups=rowpos,
> type = "a",par.settings=s,
> key = list(text=list(levels(os$rowpos)),
> lines=list(lty=s$superpose.line$lty,
> lwd=s$superpose.line$lwd,
> col= s$superpose.line$col)))
>
> --------------------------------------------------------
> R version 2.12.1 (2010-12-16)
> Platform: i386-pc-mingw32/i386 (32-bit)
>
> locale:
> [1] LC_COLLATE=German_Germany.1252 LC_CTYPE=German_Germany.1252
> [3] LC_MONETARY=German_Germany.1252 LC_NUMERIC=C
> [5] LC_TIME=German_Germany.1252
>
> attached base packages:
> [1] stats graphics grDevices datasets utils methods base
>
> other attached packages:
> [1] lattice_0.19-17
>
> loaded via a namespace (and not attached):
> [1] grid_2.12.1 tools_2.12.1
>>
>
> ______________________________________________
> R-help at r-project.org mailing list
> 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