簡體   English   中英

R中的多面板圖問題

[英]Problems with multipanel plots in R

我對多面板圖有問題。 第一個總是比其他的小一點。 我該怎么做才能使其尺寸相同? 數據打包在此文件中http://1drv.ms/1SYCyhY

我得到的情節在這里:

在此處輸入圖片說明

這是我正在使用的代碼:

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)

您忘記將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.)")

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM