在多个绘图的基础图中指定轴

时间:2016-11-02 14:07:35

标签: r plot

我试图用特定的轴制作图,同时保持纵横比为1。 问题是我不需要和想要移除的部分情节。 Example of parts to remove

我可以使用保证金管理它:

## Creating Data 
x <- seq(1, 100, length.out = 100) 
y <- seq(1, 400, length.out = 100)
## Playing with margins 
par(fin = c(3.75, 5.3) , mar = c(2, 9, 1, 3) + 0.1 )
## Making 
plot(y ~ x ,asp = 1)
abline(v = -10)
abline(v = 120)

Removed parts

但是,如果我想绘制多个图,我不知道如何删除它

## Using mfrow 
par(mfrow = c(3,2))
for (i in 1:6) {
  plot(y ~ x ,asp = 1,xlim = c(0,100), ylim = c(0,400))
  abline(v = -10)
  abline(v = 120)
}

enter image description here

我如何为多个地块做到这一点?

1 个答案:

答案 0 :(得分:0)

这可能会更接近,使用layout方法(请参阅this questionlayout R documentation)

x <- seq(1, 100, length.out = 100) 
y <- seq(1, 400, length.out = 100)

plot.new()
par(mai = c(0.6,0.5,0.3,0.3))
layout(matrix(c(1,2,3,4,5,6), nrow = 2, ncol = 3, byrow = TRUE))
for (i in 1:6) {
  plot(y ~ x ,asp = 1, ylim = c(0,400))
  abline(v = -10)
  abline(v = 120)
}

par(mai=c(b,l,t,r))选项会更改子图周围的空白大小。