我试图通过视口实现绘图窗口的简单划分,但有些事情是不对的。下面的代码想要在窗口的左手2 / 3rds中获得第一个图,在右手中获得第二个1/3。感谢我错过的想法:
pushViewport(viewport())
pushViewport(viewport(x=0, y=0, width=.66, height=1, just=c("left","top")))
plot(rnorm(100))
popViewport(1)
pushViewport(viewport(x=.66, y=0, width=.33, height=1, just=c("left","top")))
plot(1:20, 1:20, add=T)
popViewport(2)
或者我想知道是否可以用基础绘图复制以下ggplot方法。下面的代码说明了方法,但不完整 - 但是demo'd at rstudio-pubs-static。但这种方法可以转让吗?
a <- qplot(1:10, rnorm(10), main = "a")
b <- qplot(1:10, rnorm(10), main = "b")
c <- qplot(1:10, rnorm(10), main = "c")
grid.newpage()
pushViewport(viewport(layout = grid.layout(2, 2)))
vplayout <- function(x, y) viewport(layout.pos.row = x, layout.pos.col = y)
print(a, vp = vplayout(1, 1:2)) # key is to define vplayout
print(b, vp = vplayout(2, 1))
print(c, vp = vplayout(2, 2))
答案 0 :(得分:3)
如果您想使用基本图形,那么layout
是一个简单的选择:
layout(matrix(c(1, 2), 1, 2, byrow=TRUE),
widths=c(2/3, 1/3))
layout.show(n=2)
plot(rnorm(100))
plot(runif(100))