[R] Subscripting for line colors in lattice

Philippe Liège philippe.liege at anisteme.net
Thu Nov 5 16:36:19 CET 2009


Dear R-helpers,
 
 
I want to plot series in lattice, starting with symbols, then swiching to a
line.
One way is to draw symbols then to add lines.
My symbol characters and colors look good, but this is not true line colors!
I would like my lines having the same color as my symbols.  
 
 

x1 <- rep(1:90,4)
 
y1 <- c(rep(1,9),1+dnorm(-40:40/10))
y1 <- c(y1,2*y1,1.5*y1,2.5*y1)
y2<- y <- y1
y1[x1>9] <- NA
y2[x1<=9] <- NA
 
df <- data.frame(x1=x1,y1=y1,y2=y2,Type=rep(LETTERS[1:4],c(rep(90,4))),
Grain=rep(c("spelt","rye"),c(180,180)))
df
 

xyplot(y1~log(x1)|Grain, data=df,groups=Type, xlim=c(0,5),ylim=c(0,4),
cc1 = df$y1,
cc2 = df$y2,
col=trellis.par.get("superpose.line")$col[df$Type],
pch=14+as.numeric(df$Type),
panel=function(x,y,cc1,cc2,...,subscripts,groups,col,pch)
 {
 panel.xyplot(x,cc1[subscripts],type="p",col.symbol=col[subscripts],
pch=pch[subscripts] )
 panel.lines(x,cc2[subscripts],type="l",col.line=col[subscripts],
pch=pch[subscripts])
}
)

 
Regards.
 
Philippe




More information about the R-help mailing list