Skip to content

multiple graphs with a single legend and trellis graph

1 message · Gmail

#
Dear Jim,

first of all, thank you very much :) 


can you please explain me how to use split.screen?


I attach my previous graphs and my data, so you can see :)









I?m very naive and new in R :(

I really tried:

library(plotrix)
# start a wide plotting device
x11(width=10,height=4)
y<-runif(100)
oldpar<-panes(matrix(1:6,nrow=2,byrow=TRUE),widths=c(1,1,1.7))
par(mar=c(0,2,1.8,0))

mse <- plot(mse.alpha1$lambda[mse.alpha1$nsample==50],
     mse.alpha1$mse.naive[mse.alpha1$nsample==50],
     xlab=expression(paste(lambda)),ylab="MSE",type="l",col=4,lty=4, 
     xlim=c(.6,1), ylim=c(0,1), cex.lab=1.5
     #,main="yaxs default"
)
lines(mse.alpha1$lambda[mse.alpha1$nsample==50],mse.alpha1$mse.RegCal[mse.alpha1$nsample==50],col=2,lty=2)
lines(mse.alpha1$lambda[mse.alpha1$nsample==50],mse.alpha1$mse.PL[mse.alpha1$nsample==50],col=3,lty=3)
tab.title("alpha 1 N sample=50",tab.col="#88dd88",cex=1)
# tab.title("\n\n sample size=50")
# problem: when I run: tab.title("Mean squared error for ", paste(alpha[1]))",tab.col="#88dd88",cex=1)
# I get an error message: unexpected string constant in "tab.title("Mean squared error for ", paste(alpha[1]))",tab.col=""
# I searched but wasn't able to fix this one, neither the other "subtitle":
# tab.title("\n\n sample size=50")
box()


par(mar=c(0,0,1.8,0))
plot(mse.alpha1$lambda[mse.alpha1$nsample==250],
     mse.alpha1$mse.naive[mse.alpha1$nsample==250],
     xlab=expression(paste(lambda)),ylab="MSE",type="l",col=4,lty=4, 
     xlim=c(.6,1), ylim=c(0,1), cex.lab=1.5
     #,main="yaxs default"
)
lines(mse.alpha1$lambda[mse.alpha1$nsample==250],mse.alpha1$mse.RegCal[mse.alpha1$nsample==250],col=2,lty=2)
lines(mse.alpha1$lambda[mse.alpha1$nsample==250],mse.alpha1$mse.PL[mse.alpha1$nsample==250],col=3,lty=3)
tab.title ( "alpha 1 N sample=250",tab.col="#dd8800",cex=1)
box()


plot(mse.alpha1$lambda[mse.alpha1$nsample==1000],
     mse.alpha1$mse.naive[mse.alpha1$nsample== 1000],
     xlab=expression(paste(lambda)),ylab="MSE",type="l",col=4,lty=4, 
     xlim=c(.6,1), ylim=c(0,1), cex.lab=1.5
     #,main="yaxs default"
)
lines(mse.alpha1$lambda[mse.alpha1$nsample== 1000],mse.alpha1$mse.RegCal[mse.alpha1$nsample== 1000],col=2,lty=2)
lines(mse.alpha1$lambda[mse.alpha1$nsample== 1000],mse.alpha1$mse.PL[mse.alpha1$nsample== 1000],col=3,lty=3)
tab.title("alpha 1 N sample=1000",tab.col="#8888dd",cex=1)
box()



par(mar=c(2,2,1.8,0))
plot(mse.alpha2$lambda[mse.alpha2$nsample==50],
     mse.alpha2$mse.naive[mse.alpha2$nsample==50],
     xlab=expression(paste(lambda)),ylab="MSE",type="l",col=4,lty=4, 
     xlim=c(.6,1), ylim=c(0,.17), cex.lab=1.5
     #,main="yaxs default"
)
lines(mse.alpha2$lambda[mse.alpha2$nsample==50],mse.alpha2$mse.RegCal[mse.alpha2$nsample==50],col=2,lty=2)
lines(mse.alpha2$lambda[mse.alpha2$nsample==50],mse.alpha2$mse.PL[mse.alpha2$nsample==50],col=3,lty=3)
box()
tab.title("alpha 2 N sample=50",tab.col="#aabbcc",cex=1)

par(mar=c(2,0,1.8,0))
plot(mse.alpha2$lambda[mse.alpha2$nsample==250],
     mse.alpha2$mse.naive[mse.alpha2$nsample==250],
     xlab=expression(paste(lambda)),ylab="MSE",type="l",col=4,lty=4, 
     xlim=c(.6,1), ylim=c(0,.17), cex.lab=1.5
     #,main="yaxs default"
)
lines(mse.alpha2$lambda[mse.alpha2$nsample==250],mse.alpha2$mse.RegCal[mse.alpha2$nsample==250],col=2,lty=2)
lines(mse.alpha2$lambda[mse.alpha2$nsample==250],mse.alpha2$mse.PL[mse.alpha2$nsample==250],col=3,lty=3)
box()
tab.title("alpha 2 N sample=250",tab.col="#ddbc44",cex=1)


# center the title at the middle of the fifth plot
mtext("Mean Squared Error",side=1,line=0.8,cex=1.5)


par(mar=c(2,0,1.8,12))
plot(mse.alpha2$lambda[mse.alpha2$nsample==1000],
     mse.alpha2$mse.naive[mse.alpha2$nsample== 1000],
     xlab=expression(paste(lambda)),ylab="MSE",type="l",col=4,lty=4, 
     xlim=c(.6,1), ylim=c(0,.17), cex.lab=1.5
     #,main="yaxs default"
)
lines(mse.alpha2$lambda[mse.alpha2$nsample== 1000],mse.alpha2$mse.RegCal[mse.alpha2$nsample==250],col=2,lty=2)
lines(mse.alpha2$lambda[mse.alpha2$nsample== 1000],mse.alpha2$mse.PL[mse.alpha2$nsample== 1000],col=3,lty=3)
box()
tab.title("alpha 2 N sample=1000",tab.col="#ff33cc",cex=1)

legend(115,1.8,
       c("alpha 1 N sample=50","alpha 1 N sample=250","alpha 1 N sample=1000",
         "alpha 2 N sample=50","alpha 2 N sample=250","alpha 2 N sample=1000"),
       fill=c("#88dd88","#dd8800","#8888dd","#aabbcc","#ddbc44","#ff33cc"),
       xpd=NA)


legend(115,1.8,
       c("Naive", "Regression Calibration", "Pseudo Likelihood"), 
       bty = "n",col=c(4,2,3),lty=c(4,2,3),
       xpd=NA)



and I got:








Thanks again for your help ;)

Atenciosamente,
Rosa Oliveira