[R] Help needed with lattice graph!

Deepayan Sarkar deepayan at stat.wisc.edu
Fri Apr 22 22:00:44 CEST 2005


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.

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




More information about the R-help mailing list