我正在尝试使用
officer
包在PowerPoint幻灯片中绘制ggplot2
图形。实际上我已经可以做到了(直接将ggplot2
打印到ppt中),但是我需要增加ggplot2
图形的大小(用于ppt幻灯片),我了解到ggplot2
图形取决于窗口的大小(在RStudio
中)或者您导出时设置的大小,因此我正在寻找一种方法:(1)以给定的大小导出ggplot2
图形(例如:height=5, width=8
),(2)从ppt代码中导入/读取。library(officer)
library(devEMF)
library(magrittr)
library(ggplot2)
t <- "../example.pptx"
filename <- gg
read_pptx() %>%
add_slide(layout = "Title and Content", master = "Office Theme") %>%
ph_with_img(src = filename, width = 6, height = 4, type = "body") %>%
print(target = t)
gg
是 ggplot2 中的任何一个图表(实际上并不重要)。t
是输出文件的地址。
ph_with_img
PowerPoint 文档和图形
注:如果有我不知道的包或命令,可以直接编辑 ggplot2 的大小,那么以上所有内容都是不必要的。
png()
和width = 8,height = 5
。 - erc