将行多图以1:1的比例保存到R中的PDF中

问题描述 投票:1回答:1

我正在尝试在R中以行网格形式排列的三个绘图中生成PDF图像。这是我尝试过的:

pdf("fig.pdf")
par(mfrow=c(1,3))
plot(rnorm(100), rnorm(100), xlab="Something on X", ylab="Some on Y", main="This is it 1")
plot(rnorm(100), rnorm(100), xlab="Something on X", ylab="Some on Y", main="This is it 2")
plot(rnorm(100), rnorm(100), xlab="Something on X", ylab="Some on Y", main="This is it 3")
dev.off()

但是它产生:

enter image description here

虽然我希望每个图都为正方形,并且最终图像不具有1:1的比例:

enter image description here


尝试

我尝试过:

pdf("fig.pdf", width = 3, height = 1)

但是在绘制每个图时,这会产生错误,抱怨尺寸不够:

plot.new()中的错误:图形边距太大

如果我尝试:

par(mfrow=c(1,3), pty='s')

然后:

enter image description here

如何实现(可能不使用外部库,而是简单的基本默认R包)?

r plot
1个回答
1
投票

我用过

pdf("fig.pdf", width=6, height=2.4)
par(mfrow=c(1,3))
plot(rnorm(100), rnorm(100), xlab="Something on X", ylab="Some on Y", main="This is it 1")
plot(rnorm(100), rnorm(100), xlab="Something on X", ylab="Some on Y", main="This is it 2")
plot(rnorm(100), rnorm(100), xlab="Something on X", ylab="Some on Y", main="This is it 3")
dev.off()

并且得到了:

Three square plots

© www.soinside.com 2019 - 2024. All rights reserved.