在R中将文本框保存为pdf [英] Saving a text box to pdf in R

查看:268
本文介绍了在R中将文本框保存为pdf的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在R中创建项目符号类型列表,并希望将其保存为pdf,这成功导致在窗口上打印项目符号列表:

I am trying to create a bullet-point type list in R, and want to save it in pdf, which successfully resulted in printing the bullet-point list on a window:

 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.

However, I would like to be able to save this to a pdf, along with two other graphs on the same page.

有什么办法吗?谢谢!

推荐答案

尝试如下操作:

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()

这是大概的输出:

这篇关于在R中将文本框保存为pdf的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆