保存文本框R中的PDF(Saving a text box to pdf in R)

2019-10-18 19:51发布

我试图创建R A要点的类型列表,并希望将其保存为PDF,它成功地导致打印窗口上的子弹点列表:

 a = paste0("Starting portfolio value: $", prettyNum(1000000,big.mark=",",scientific=F))
 b = "Inflation assumptions of 3% annually"
 c = "Average annual returns: 6%"
 d ="Average annual volatility: 7%"

 text = paste(a, "\n", b, "\n", c, "\n", d, "\n")

 library(grid)
 grid.points(x = rep(10,4), y = c(295, 318, 338, 360), pch = 15, gp = gpar(cex = 0.5))
 grid.text(text, x = 0.05, hjust = 0, gp = gpar(fontsize = 11))

不过,我想能够将此保存为PDF,与同一页面上的其他两个图形一起。

这样做的方法吗? 谢谢!

Answer 1:

尝试是这样的:

a = paste0("Starting portfolio value: $", prettyNum(1000000,big.mark=",",scientific=F))
b = "Inflation assumptions of 3% annually"
c = "Average annual returns: 6%"
d ="Average annual volatility: 7%"

pdf('out.pdf',width=5,height=5)
plot(NA, xlim=c(0,5), ylim=c(0,5), bty='n',
     xaxt='n', yaxt='n', xlab='', ylab='')
text(1,4,a, pos=4)
text(1,3,b, pos=4)
text(1,2,c, pos=4)
text(1,1,d, pos=4)
points(rep(1,4),1:4, pch=15)
dev.off()

下面是近似的输出:



文章来源: Saving a text box to pdf in R
标签: r text r-grid