分享

R语言直接将图片导出至pptx或docx

 iceer1212 2020-07-10

在之前学习的时候,老师有推荐"export"这个神器可以将图片直接导出至ppt,但是发现3.6及4.0版本的R语言仍然无法使用export。
因此,切换至另外一个叫"eoffice"的package。
安装eoffice

install.packages("eoffice") 

报错

ERROR: configuration failed for package ‘magick’
Warning in install.packages :
  installation of package ‘magick’ had non-zero exit status
ERROR: dependency ‘magick’ is not available for package ‘eoffice’
Warning in install.packages :
  installation of package ‘eoffice’ had non-zero exit status

查看错误内容是因为没有安装Magick++

Configuration failed to find the Magick++ library. Try installing:
 - deb: libmagick++-dev (Debian, Ubuntu)
 - rpm: ImageMagick-c++-devel (Fedora, CentOS, RHEL)
 - csw: imagemagick_dev (Solaris)
 - brew imagemagick@6 (MacOS)

按照提示安装libmagick++-dev

sudo apt-get install libmagick++-dev

之后就可以加载

library(eoffice)

保存至ppt可使用topptx

topptx(filename ="mtcars.pptx")

保存至doxc可使用todocx

 todocx(filename = "mtcars.docx")

支持多处方式输出图片

p <- ggplot(mtcars, aes(mpg, disp, color = factor(cyl))) + geom_point()
topptx(p, filename = "mtcars.pptx"), width = 6, height = 4)

也支持表格从ppt或者word的输出和读取

totable(head(mtcars), filename = "mtcars.pptx")

以及输出多种图片格式

tofigure(p, filename = "mtcars.pdf")

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多