[R] xyplot and subscripts

Deepayan Sarkar deepayan.sarkar at gmail.com
Thu Aug 13 19:25:36 CEST 2009


On Thu, Aug 6, 2009 at 7:27 AM, Kito Palaxou<kitopalaxou at yahoo.com> wrote:
>
> Hi all,
>
> I have a data frame like this:
>
> DF <- data.frame(x = rnorm(10), y = rnorm(10), gr = rep(1:5, 2))
>
> and I make the following xy-plot:
>
> library(lattice)
> xyplot(y ~ x, data = DF, groups = gr, type = "b", col = 1)
>
>
> Is it possible that the two points that belong to the same group specified by
> DF$gr to have a different color -- that is for each pair of points connected by
> the line, I want one to be black and the other red. I tried:

[Sorry for the late reply, I seem to have missed your mail before.]

You will need to handle color in a custom panel.groups function:

xyplot(y ~ x, data = DF, groups = gr, type = "b",
       panel = panel.superpose,
       panel.groups = function(x, y, ...) {
           panel.lines(x, y, col = "black")
           panel.points(x, y, pch = 16, col = c("black", "red"))
       })

-Deepayan




More information about the R-help mailing list