[英]automatically adjust R plot size in a PDF output
當使用R中的pdf()
函數在外部文件中保存繪圖時,我們可以指定width
和/或height
來調整繪圖的大小。 但是,有些情況下我們獲得多個圖(比如使用par(mfrow=c(2,4))
)。 在這種情況下,要確定PDF文件的最佳width
和height
是多么困難,以便正確顯示所有圖形。 有沒有辦法讓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.