[R] Help needed with lattice graph!

Paul Murrell p.murrell at auckland.ac.nz
Fri Apr 22 22:39:17 CEST 2005


Hi


Deepayan Sarkar wrote:
> On Friday 22 April 2005 03:29, Sander Oom wrote:
> 
>>Dear R users,
>>
>>If I manage to sort out this graph, it is certainly a candidate for the
>>new R graph gallery
>>(http://addictedtor.free.fr/graphiques/displayGallery.php)!
>>
>>I created the following lattice graph:
>>
>>library(lattice)
>>tmp <- expand.grid(geology = c("Sand","Clay","Silt","Rock"),
>>   species =
>>c("ArisDiff","BracSera","CynDact","ElioMuti","EragCurS","EragPseu"),
>>   dist = seq(1,9,1) )
>>tmp$height <- rnorm(216)
>>sps <- trellis.par.get("superpose.symbol")
>>sps$pch <- 1:6
>>trellis.par.set("superpose.symbol", sps)
>>   xyplot( height ~ dist | geology, data = tmp,
>>     groups = species, type = "b", cex = 1.2,
>>     layout = c(2,2),
>>     lines = list(col="grey"),
>>     key = list(columns = 2, type = "b", cex = 1.2,
>>       text = list(paste(unique(tmp$species))),
>>       points = Rows(sps, 1:6)
>>       )
>>   )
> 
> 
> I would do something like this instead:
> 
> ---------------------------
> 
> library(lattice)
> lattice.options(default.theme = canonical.theme(color = FALSE))
> 
> 
> tmp <-
>     expand.grid(geology = c("Sand","Clay","Silt","Rock"),
>                 species = c("ArisDiff", "BracSera", "CynDact", 
>                             "ElioMuti", "EragCurS", "EragPseu"),
>                 dist = seq(1,9,1) )
> 
> tmp$height <- rnorm(216)
> 
> 
> sp <- list(superpose.symbol = list(pch = 1:6, cex = 1.2),
>            superpose.line = list(col = "grey", lty = 1))
> 
> xyplot(height ~ dist | geology, data = tmp,
>        groups = species,
>        type = "b", 
>        layout = c(2,2),
>        par.settings = sp,
>        auto.key = list(columns = 2, lines = TRUE))
> 
> -------------------------
> 
> 
>>However, for once, the R defaults are not to my liking. I plot the graph
>>to postscript and the result is less then optimal.
>>
>>I would like to plot the point symbols in black and white, both in the
>>graphs and the key. I would like the lines to be a single style (grey or
>>a light dash) and preferably the lines do not go through the symbols
>>(like figure 4.11 in the MASS book).
> 
> 
> 
> type='b' is the right choice, and it works in standard graphics, but not in 
> lattice (where it's same as type='o'). If you really want it, bug Paul to add 
> support for it in grid.


[Paul exhibits bug-avoidance behaviour by suggesting a low-level 
workaround ...]

xyplot(height ~ dist | geology, data = tmp,
        groups = species,
        layout = c(2,2),
        panel = function(x, y, type, ...) {
          panel.superpose(x, y, type="l", ...)
          lpoints(x, y, pch=16, col="white", cex=2)
          panel.superpose(x, y, type="p"...)
        },
        par.settings = sp,
        auto.key = list(columns = 2, lines = TRUE))



> To get the points and lines combined in the key, you could do 
> 
> xyplot(height ~ dist | geology, data = tmp,
>        groups = species,
>        type = "b", 
>        layout = c(2,2),
>        par.settings = sp,
>        key =
>        list(columns = 2, 
>             lines = list(col="grey", type = "b", cex = 1.2, pch = 1:6),
>             text = list(levels(tmp$species))))
> 
> but evidently there's no way to separately control the color of the line and 
> the points on it.
> 
> Deepayan
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


-- 
Dr Paul Murrell
Department of Statistics
The University of Auckland
Private Bag 92019
Auckland
New Zealand
64 9 3737599 x85392
paul at stat.auckland.ac.nz
http://www.stat.auckland.ac.nz/~paul/




More information about the R-help mailing list