[R] trellis plot

Sebastián Daza sebastian.daza at gmail.com
Mon Mar 26 06:20:21 CEST 2012


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")



Thank you in advance!

-- 
Sebastián Daza



More information about the R-help mailing list