[R] Help needed with lattice graph!

Romain Francois francoisromain at free.fr
Fri Apr 22 23:31:28 CEST 2005


Well done !

The result of your work has been uploaded to the gallery (graph 48).

Romain

Le 22.04.2005 22:39, Paul Murrell a écrit :

> 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
>
>
>


-- 
~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~
~~~~~~      Romain FRANCOIS - http://addictedtor.free.fr         ~~~~~~
~~~~        Etudiant  ISUP - CS3 - Industrie et Services           ~~~~
~~                http://www.isup.cicrp.jussieu.fr/                  ~~
~~~~           Stagiaire INRIA Futurs - Equipe SELECT              ~~~~
~~~~~~   http://www.inria.fr/recherche/equipes/select.fr.html    ~~~~~~
~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~




More information about the R-help mailing list