繁体   English   中英

自动调整PDF输出中的R绘图大小

[英]automatically adjust R plot size in a PDF output

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

用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")

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM