On Thu, Aug 6, 2009 at 7:27 AM, Kito Palaxou<kitopala...@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

______________________________________________
R-help@r-project.org 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.

Reply via email to