gpt4 book ai didi

r - 如何在 R 中使用布局调整行宽

转载 作者:行者123 更新时间:2023-12-01 23:47:15 25 4
gpt4 key购买 nike

我有 8 个图,我想将它们全部绘制在一页上。每个图都是使用基础图形制作的,我宁愿坚持使用它而不是使用 latticeggplot

下面的方案是一个页面,其中每个数字表示哪个图 # 占据了该页面的比例。有什么方法可以用 layout 或任何其他基本函数来做到这一点吗?

1111122
3333444
5556666
7788888

我目前的一些代码:

pdf("test.pdf",height=30,width=10)
widths = c(5/7,2/7,4/7,3/7,3/7,4/7,2/7 5/7) # this doesn't work

x=layout(matrix(1:8,nrow=4,ncol=2,byrow=T), widths=widths,
heights=rep(1/4,4))

for (ix in 1:4){

plot(rnorm(100))
plot(rnorm(100))
}
dev.off()

最佳答案

您可以为布局指定矩阵并使用layout 函数。

mat <- t(sapply(1:4, function(x) 
rep.int(c((x - 1) * 2 + 1, (x - 1) * 2 + 2), c(6 - x, 1 + x))))
# [,1] [,2] [,3] [,4] [,5] [,6] [,7]
# [1,] 1 1 1 1 1 2 2
# [2,] 3 3 3 3 4 4 4
# [3,] 5 5 5 6 6 6 6
# [4,] 7 7 8 8 8 8 8

layout(mat)

for (i in 1:8) {
plot(rnorm(10))
}

如果相同的数字在布局矩阵中重复出现,则绘图使用与该数字对应的空间。

enter image description here

关于r - 如何在 R 中使用布局调整行宽,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28415039/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com