[R] trellis.par.set and grid : how to set by default that I want a grid on my graphes ?
Gabor Grothendieck
ggrothendieck at gmail.com
Wed Nov 15 14:36:27 CET 2006
1. Another way to address this is to include "g" in the type vector:
xyplot(Sepal.Length + Sepal.Width ~ Petal.Length ,
data = iris, allow.multiple = TRUE, scales = "same", type = c("l", "g"))
2. Also look in the example section of:
library(zoo)
?xyplot.zoo
which gives an example of plotting a grid behind an existing plot. You
could define a function to do that and then just call it after your xyplot call.
3. You could define your own panel function:
mypanel <- function(...) { panel.grid(); panel.superpose(...) }
so that you only have to write panel = mypanel in the arg list.
4. You could define your own xyplot2 which calls xyplot and uses one
of the above methods to ensure that it does it with a grid.
On 11/15/06, Pascal Boisson <hoothootprod at gmail.com> wrote:
> Hello all,
>
> I want to draw a grid behind my graphes, using lattice package.
> I manage to do it with instructions like this one :
>
> xyplot(Sepal.Length + Sepal.Width ~ Petal.Length ,
> data = iris, allow.multiple = TRUE, scales = "same",type="l",
> panel = function(...) { panel.grid(h=-1, v= -1) ;
> panel.superpose(...)
> }
> )
>
> I was wondering if there were a way to do it using for example
> trellis.par.set() to set this by default, like what I do for colors e.g. :
> trellis.par.set(list(superpose.line = list(col = c( "red", "yellow",
> "green", "blue", "purple", "orange", "black", "maroon", "pink", "cyan",
> "grey", "magenta" ))))
>
> instead of using in each call this log panel = function (...) { }
> instruction
>
> I tried emprirically
> trellis.par.set(list(grid.pars= list(h = -1, v=-1)))
>
> with no success (I am not even sure that this grid.pars is about drawing
> grids ... but it is the nearest instruction i found in trellis parameters
>
> As i am not very confident with this trellis.par.set(), I might have missed
> something ... I also tried to define a function
>
> grid<-function(...) { panel.grid(h=-1, v= -1) ; panel.superpose(...) }
>
> xyplot(Sepal.Length + Sepal.Width ~ Petal.Length ,
> data = iris, allow.multiple = TRUE, scales = "same",type="l",
> panel = grid() #also tried grid(...)
> )
>
> but the only result is an arror message
> with grid() : " Erreur dans unit(y0, default.units) : 'x' et 'units' doivent
> avoir une longueur positive " (x and units should have a positive length)
> with grid(...) : " '...' utilisé dans un contexte incorrect " ('...' used in
> a wrong context)
>
> Could anyone tell me a way of doing it ?
>
>
>
>
>
> --
> Pascal Boisson
> hoothootprod at gmail.com
> http://pak.enroweb.com
> http://www.flickr.com/photos/hoothootprod/
>
> [[alternative HTML version deleted]]
>
>
>
> ______________________________________________
> 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
> and provide commented, minimal, self-contained, reproducible code.
>
>
>
More information about the R-help
mailing list