如何在 R 中使用 Pdftools 从 pdf 转换为 png 时获得完整的 ggplot?

问题描述

我有从 rmd 文件呈现的 pdf 文件,并且在将 pdf 页面转换为 png 时遇到问题。在我演示了一个类似的问题以便更好地理解之后:

我生成了一个 ggplot 并保存为 pdf(mtcars.pdf)。

a <- ggplot(mtcars,aes(x=wt,y=mpg)) + geom_point() +
  ggtitle("Fuel Efficiency of 32 Cars") +
  xlab("Weight (x1000 lb)") + ylab("Miles per Gallon") +
  theme(text=element_text(family="Times New Roman"))
print(a)

mtcars.pdf 如下:

enter image description here

现在我正在尝试使用 pdftools 的 pdf_convert 函数将 pdf 转换为 png 文件。

pdfs <- c("mtcars.pdf")
library(pdftools)
sapply(pdfs,function(x)
  pdf_convert(x,format = "png",pages = 1,filenames = NULL,dpi = 300,opw = "",upw = "",verbose = TRUE))

但我得到的图没有任何轴上的文本数据,并收到如下错误消息:

“正在将第 1 页转换为 mtcars_1.png...PDF 错误:找不到 'TimesNewRomanPSMT' 的字体”

我尝试了其他几种字体,但 pdf_convert 函数无法识别其中任何一种。它给出的输出图像如下:

enter image description here

有什么方法可以将 ggplot 的所有内容从 pdf 转换为 png?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...