[R] Legend symbols (line, points) in one column.

Kenneth Roy Cabrera Torres krcabrer at une.net.co
Thu Oct 13 14:00:36 CEST 2011


Dear R users:

I want to have in the same column both symbols, line and
points, one for a data, and the other for the model.

How can I do that?

Or is there other better form to show both data and model
in the same graphic? I need to make the difference on time
of the same subject (repeated measurements on time)


Problem example:
###########################################################
x<-1:5
y<-1*x+rnorm(10)
data1<-data.frame(x,y,type=rep("data",length(x)))
model1<-lm(y~x,data=data1)
data2<-data.frame(x=seq(0,6,.1))
data2$y<-predict(model1,newdata=data2)
data2$type<-rep("model",nrow(data2))
dataT<-rbind(data1,data2)
dataT

require(lattice)
confMisc1<- simpleTheme(pch = c(19,1),lwd=c(2,1),cex=1.5,
            lty=1,col=c("black"))
xyplot(y~x,group=type,
       type=c("p","l"),
       key=list(space="right",text=list(c("Data","Model")),
               points=list(pch=c(as.integer(NA),19)),
               lines=list(lty=c(1,0),lwd=c(2,0))),
       par.settings=confMisc1,
       panel=panel.superpose,
       distribute.type=TRUE,       
       data=dataT)
###########################################################



More information about the R-help mailing list