[R] lattice.xyplot: adding grid lines

Deepayan Sarkar deepayan at stat.wisc.edu
Tue Sep 9 15:03:06 CEST 2003


On Tuesday 09 September 2003 04:49, Marc Mamin wrote:
> Hallo,
>
> I'd like to add grid lines to a lattice graph having 2 series of Y data.
>
> See these 2 examples:
>
>
>
> data(iris)
>
> [1]
> xyplot(Sepal.Length + Sepal.Width ~ Petal.Length ,
>             data = iris, allow.multiple = TRUE, scales = "same",type="l",
> )
>
>
> [2]
> xyplot(Sepal.Length + Sepal.Width ~ Petal.Length ,
>             data = iris, allow.multiple = TRUE, scales = "same",type="l",
> panel = function(x, y) {
>   panel.grid(h=2, v= 3)
>    panel.xyplot(x, y)
>   }
> )
>
>
> Question:  is it possible to keep all the formats of example [1] (colors,
> type="l", ...), and just add the grids appearing in example 2.
> Moreover I'd like to choose the color of the grid...

Something like this should work:

xyplot(Sepal.Length + Sepal.Width ~ Petal.Length ,
       data = iris, allow.multiple = TRUE, scales = "same",type="l",
       panel = function(...) {
           panel.grid(h=2, v= 3, col="blue")
           panel.xyplot(...)
       }
)

Deepayan




More information about the R-help mailing list