16

当使用pdf()R 中的函数将绘图保存在外部文件中时,我们可以指定width和/或height调整绘图的大小。但是,在某些情况下,我们会获得多个图(例如使用par(mfrow=c(2,4)))。在这种情况下,很难确定什么是最好的widthheight对于 PDF 文件,以便正确显示所有绘图。有没有办法让 R 在 PDF 文件中自动“拟合图”?我搜索了其中的论点pdf()并尝试了一些,但结果并不令人满意。非常感谢你!

4

1 回答 1

3

使用ggplot怎么样?

require(ggplot2)

# Bogus data
x <- rnorm(10000)
y <- as.factor(round(rnorm(10000, mean=10, sd=2), 0))
df <- data.frame(vals=x, factors=y)

myplot <- ggplot(data=df, aes(x=vals)) +
  geom_density() +
  facet_wrap(~ factors)

ggsave(filename="~/foo.pdf", plot=myplot, width=8, height=10, units="in")

编辑:如果您需要打印多页,请参阅此问题

于 2012-10-19T14:17:58.467 回答