I'm not sure how to do this in lattice, but here is an option
with ggplot2.
library(ggplot2)
set.seed(123)
# Make sure the data has a variable that indicates
# which group is red and which one is black
DF <- data.frame(x = rnorm(10), y = rnorm(10), gr = rep(1:5,
2),endpoint = c(rep("Red_Group",5),rep("Black_Group",5)))
p <- ggplot(DF,aes(x=x,y=y,group=gr))
p <- p+geom_line()
p <- p + geom_point(aes(colour=endpoint))
# Manually specify that you want the colors to be black and red
p <- p + scale_colour_manual("endpoint", c("Black_Group"
= "black",
"Red_Group" = "red"))
p
Best,
Juliet
On Thu, Aug 6, 2009 at 10: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:
>
> xyplot(y ~ x, data = DF, groups = gr, type = "b", col = 1:2)
>
>
> but it doen't work. Is there any solution for this??
>
> Thanks a lot!
>
> Kito
>
> ______________________________________________
> R-help at 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.
>