2017-02-19 67 views
1

我想知道如何使用下面的矩阵结构将BELOW 3 R图合并到一个屏幕中?在一个屏幕中包含3个不同的R图

注:我已经注解了代码,但最好的方法是运行每个图以查看它的外观。

这里是我的R代码里面:

m2 <- matrix(c(0,2,2,2,2,  1,2,2,2,2,  1,2,2,2,2,  0,2,2,2,2 ), nrow=5, ncol=4) # matrix m2 

m3 <- matrix(c(0,2,2,2,2,0, 1,2,2,2,2,3, 1,2,2,2,2,3, 0,2,2,2,2,0), nrow=6, ncol=4) # matrix m3 

TL <- T ## NOW TRUE 

if(TL==T) {layout(m3)}else{layout(m2)} ## IF TL==T, split the screen according to *m3* 


## Plot # 1: ############################################### 
curve(dcauchy(x,0,1),-6,6,yaxt="n",bty="n",xaxs="i",xlab="GG",font.lab=2,lwd=2,col="cyan2",ylab = "") 


## Plot #2: ############################################### 
plot(1, 1, type = "n", xlim = c(0,1.5), ylim = c(.01, 3),log="y", bty="n", axes=F, xaxs="i", 
xlab = "GGG", ylab=expression(paste(bold('BBB'))),font.lab=2,cex.lab=2) 


axis(side=1, at = seq(0,1.5,.25),labels = c("0",".25",".5",".75","1","1.25","1.5")) 
axis(side=2, at = c(.01, 1/30, 1/10, 1/3, 1, 3),labels = c("1/100", "1/30", "1/10", "1/3", "1", "3"),las=1) 

axis(side=4,at = c(.01, 1/30, 1/10, 1/3, 1,3),labels = F) 
axis(side=4,at = c(.01*1.8, (1/30)*1.7, (1/10)*1.8, (1/3)*1.7, 1*1.7), c("YES", "NO", "YES", "NO", "NO"),tick=F,las=1,font=2, 
mgp=c(1.5,.3, 0),cex.axis=1.8) 


## Plot #3: ############################################### 
ci <- c(0.09253967, 0.48434172) 
plot(1, 1, ty="n" ,ann=F, yaxt="n", bty="n", xlim=c(ci[1], ci[2]), ylim=c(0, 1), xaxt="n") 
axis(side = 1, at = ci) 
arrows(ci[1], .01, ci[2], .01, code=3, lwd=2, angle = 90, length = .08) 
mtext(side=1,"GGG",line=2.8, font=2, cex= 1.5) 

回答

1

尝试指定的高度和宽度参数layout:我有什么可能是接近你的目标:

png(height=11, width=8, units="in", res=72) 
if(TL) {layout(m3, widths=c(3, 2,2,3), heights=rep(1.2, ncol(m3))) 
      }else{ 
       layout(m2)} 
    #.... your code here 
dev.off() 

可能仍然需要一些调整的边缘或mtext的位置,因为边上的超大字母似乎扩大了绘制区域的边缘。

enter image description here

+0

非常感谢!有什么方法可以在'layout()'流体中创建'width ='和'height ='参数吗?我的意思是如果剧情以任何方式改变,这两个参数会自动调整自己? – rnorouzian

+0

宽度和高度的默认值是一系列1重复正确数量的行和列,所以您需要更具体地说明您希望的是什么样的“流动性”。 –

+0

我使用'png'的唯一原因是创建一个可以看到的图像。您应该能够设置您的操作系统特定的交互式屏幕设备,以具有足够的尺寸来容纳这些图。 –