On 2012-03-25 21:20, Sebastián Daza wrote:
Hi everyone,
I am just trying to figure out how to do a xyplot where in addition to
dots and lines I can change dots' colors according to an individual
variable (e.g., marital disruption across time, a dummy 0/1). When I
use "groups" specification (see below), I get two different lines for
each individual based on groups, and what I want is to get one line
connecting dots, and different dots' colors according to marital
disruption.
Any ideas about how to do that?
person<- rep(1:2, each=4)
income<- c(100, 120, 150, 200, 90, 100,120, 150)
disruption<- rep(c(0,1), 4)
time<- rep(c(1:4),2)
dat<- as.data.frame(cbind(person,time, income, disruption))
library(lattice)
xyplot(income~time|as.factor(person),data=dat,
type=c("p","g","o"), col.line="black",
xlab="Time",
ylab="Familiar Income")
# I just want to change dots' colors according to disruption, not to
get two different lines:
xyplot(income~time|as.factor(person),data=dat,
type=c("p","g","o"), col.line="black", groups=disruption,
xlab="Time",
ylab="Familiar Income")
If I understand correctly what you're after, try adding the
'col.symbol' argument instead of the 'groups' argument.
col.symbol = disruption + 1
or, better, for arbitrary colours:
mycols <- c(2, 5)
xyplot(....,
col.symbol = mycols[disruption + 1],
....)
Peter Ehlers
Thank you in advance!
______________________________________________
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.