Kenneth Roy Cabrera Torres
2011-Oct-13 12:00 UTC
[R] Legend symbols (line, points) in one column.
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) ###########################################################
R. Michael Weylandt
2011-Oct-14 02:40 UTC
[R] Legend symbols (line, points) in one column.
Looking at your provided example (thank you!), I'm not entirely sure what you want to put in the same column. Could you perhaps clarify -- is it something about the plot itself or the legend? Michael> > On Thu, Oct 13, 2011 at 8:00 AM, Kenneth Roy Cabrera Torres > <krcabrer at une.net.co> wrote: >> 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) >> ########################################################### >> >> ______________________________________________ >> 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. >> >