R中多面图的问题

时间:2015-06-04 16:44:53

标签: r plot graphing

我遇到了多面板图的问题。第一个总是比其他的小一点。我应该怎么做才能使它大小相同? 数据打包在此文件中 http://1drv.ms/1SYCyhY

我得到的情节是:

enter image description here

这是我正在使用的代码:

P2_TRF<-read.table("P2.txt",sep = "\t",header=F)
P3_TRF<-read.table("P3.txt",sep = "\t",header=F)
P4_TRF<-read.table("P4.txt",sep = "\t",header=F)
P5_TRF<-read.table("P5.txt",sep = "\t",header=F)
P6_TRF<-read.table("P5.txt",sep = "\t",header=F)    

windows(width=20,height=5)
opar <- par(no.readonly=TRUE)
par(mfrow=c(1,10))
par(pin=c(4,3),oma=c(4,4,3,0),mar=c(0,0,0,0.5))

plot(P2_TRF$V1,P2_TRF$V2,type="l",lwd=1.5,ann=F,
      col="red",cex.axis=1.2,cex.lab=1.3,family="sans",
      pch=19,axes=F, frame.plot=TRUE,xlim=c(0,11),ylim=c(0,6.5))
mtext("0-2min",side=3,,font=2,line=-2,cex=0.8)
mtext("Intensity (a.u.)",side=2,line=2,font=2,cex=0.8)
par(tcl= -0.5,cex=0.5)
axis(1,at=seq(0,10,by=2),lwd=1,lwd.ticks=1)
par(tcl= -0.5,cex=0.5)
axis(2,at=seq(0,6,by=2),las="2")

plot(P2_TRF$V3,P2_TRF$V4,type="l",lwd=1.5,ann=F,
     col="red",cex.axis=1.2,cex.lab=1.3,family="sans",
     pch=19,axes=F, frame.plot=TRUE,xlim=c(0,11),ylim=c(0,6.5))
mtext("2-4min",side=3,,font=2,line=-2,cex=0.8)
par(tcl= -0.5,cex=0.5)
axis(1,at=seq(0,10,by=2),lwd=1,lwd.ticks=1)

plot(P2_TRF$V5,P2_TRF$V6,type="l",lwd=1.5,ann=F,
     col="red",cex.axis=1.2,cex.lab=1.3,family="sans",
     pch=19,axes=F, frame.plot=TRUE,xlim=c(0,11),ylim=c(0,6.5))
mtext("4-6min",side=3,,font=2,line=-2,cex=0.8)
par(tcl= -0.5,cex=0.5)
axis(1,at=seq(0,10,by=2),lwd=1,lwd.ticks=1)

plot(P2_TRF$V7,P2_TRF$V8,type="l",lwd=1.5,ann=F,
     col="red",cex.axis=1.2,cex.lab=1.3,family="sans",
     pch=19,axes=F, frame.plot=TRUE,xlim=c(0,11),ylim=c(0,6.5))
mtext("6-8min",side=3,,font=2,line=-2,cex=0.8)
par(tcl= -0.5,cex=0.5)
axis(1,at=seq(0,10,by=2),lwd=1,lwd.ticks=1)

plot(P2_TRF$V9,P2_TRF$V10,type="l",lwd=1.5,ann=F,
     col="red",cex.axis=1.2,cex.lab=1.3,family="sans",
     pch=19,axes=F, frame.plot=TRUE,xlim=c(0,11),ylim=c(0,6.5))
mtext("8-10min",side=3,,font=2,line=-2,cex=0.8)
mtext("1h15m",side=3,,font=2,line=1,cex=0.8)
mtext("Time (ms)",side=1,line=3,font=2,cex=0.8)
par(tcl= -0.5,cex=0.5)
axis(1,at=seq(0,10,by=2),lwd=1,lwd.ticks=1)

plot(P2_TRF$V11,P2_TRF$V12,type="l",lwd=1.5,ann=F,
     col="red",cex.axis=1.2,cex.lab=1.3,family="sans",
     pch=19,axes=F, frame.plot=TRUE,xlim=c(0,11),ylim=c(0,6.5))
mtext("10-12min",side=3,,font=2,line=-2,cex=0.8)
par(tcl= -0.5,cex=0.5)
axis(1,at=seq(0,10,by=2),lwd=1,lwd.ticks=1)

plot(P2_TRF$V13,P2_TRF$V14,type="l",lwd=1.5,ann=F,
     col="red",cex.axis=1.2,cex.lab=1.3,family="sans",
     pch=19,axes=F, frame.plot=TRUE,xlim=c(0,11),ylim=c(0,6.5))
mtext("12-14min",side=3,,font=2,line=-2,cex=0.8)
par(tcl= -0.5,cex=0.5)
axis(1,at=seq(0,10,by=2),lwd=1,lwd.ticks=1)

plot(P2_TRF$V15,P2_TRF$V16,type="l",lwd=1.5,ann=F,
     col="red",cex.axis=1.2,cex.lab=1.3,family="sans",
     pch=19,axes=F, frame.plot=TRUE,xlim=c(0,11),ylim=c(0,6.5))
mtext("14-16min",side=3,,font=2,line=-2,cex=0.8)
par(tcl= -0.5,cex=0.5)
axis(1,at=seq(0,10,by=2),lwd=1,lwd.ticks=1)

plot(P2_TRF$V17,P2_TRF$V18,type="l",lwd=1.5,ann=F,
     col="red",cex.axis=1.2,cex.lab=1.3,family="sans",
     pch=19,axes=F, frame.plot=TRUE,xlim=c(0,11),ylim=c(0,6.5))
mtext("16-18min",side=3,,font=2,line=-2,cex=0.8)
par(tcl= -0.5,cex=0.5)
axis(1,at=seq(0,10,by=2),lwd=1,lwd.ticks=1)

plot(P2_TRF$V19,P2_TRF$V20,type="l",lwd=1.5,ann=F,
     col="red",cex.axis=1.2,cex.lab=1.3,family="sans",
     pch=19,axes=F, frame.plot=TRUE,xlim=c(0,11),ylim=c(0,6.5))
mtext("18-20min",side=3,,font=2,line=-2,cex=0.8)
par(tcl= -0.5,cex=0.5)
axis(1,at=seq(0,10,by=2),lwd=1,lwd.ticks=1)
par(opar)

1 个答案:

答案 0 :(得分:1)

你忘了在第一个情节之前放par(tcl= -0.5,cex=0.5)。此选项可用于剩余的图表,因此无需重复。

作为旁注,避免复制和粘贴这么多,并使用函数包装来避免一直以相同的方式重置函数参数。例如

myplot <- function(x, y, mtext1, mtext2) {
    plot(x, y, type="l",lwd=1.5,ann=F,
         col="red",cex.axis=1.2,cex.lab=1.3,family="sans",
         pch=19,axes=F, frame.plot=TRUE,xlim=c(0,11),ylim=c(0,6.5))
    mtext(mtext1,side=3,,font=2,line=-2,cex=0.8)
    mtext(mtext2,side=2,line=2,font=2,cex=0.8)
}

现在每个情节都是单行,下面是第一个情节的代码。

myplot(P2_TRF$V1, P2_TRF$V2, "0-2min", "Intensity (a.u.)")