【问题标题】:Problems with multipanel plots in RR中的多面板图问题
【发布时间】:2015-06-04 16:44:52
【问题描述】:

我对多面板图有疑问。第一个总是比其他的小一点。我应该怎么做才能使其大小相同? 数据打包在这个文件中 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)

【问题讨论】:

  • 问题是由于y轴标签和刻度占用的空间。基础图形中有一些变通方法,但你反对 ggplot 吗?它很容易处理这样的事情(尽管我们需要先转换一下您的数据)。
  • ggplot 会是一个很好的学习方法。我读了一点。但是我刚刚开始学习 R。所以,我以后可能会看看它。无论如何,非常感谢您的时间和精力。

标签: r plot graphing


【解决方案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.)")

【讨论】:

  • 抱歉,我发现我的代码如此粗糙和笨拙。我是自学初学者。所以还是很糟糕。你的 cmets 是完美的。我试图修改我的代码,现在它更容易工作了。现在我知道如何使用函数()了。非常感谢您的指导!
  • 它修复了你的第一个子情节吗?
  • 是的,一切都很完美。抱歉回复晚了!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多