gpt4 book ai didi

r - 在给定大小的 powerpoint 幻灯片中绘制 ggplot2 图 - R

转载 作者:行者123 更新时间:2023-12-05 08:40:43 33 4
gpt4 key购买 nike

我正在尝试使用 officer 包在幻灯片中绘制 ggplot2 图。我实际上可以做到(直接在 ppt 中打印 ggplot2),但是因为我需要增加 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 documents and graphics

PD:如果有一些我不知道但仍然找不到的包/命令,那么所有这些都是不必要的,我可以在其中编辑 ggplot2 的大小。

最佳答案

我刚刚在 officer 之上制作了一个新包 export ,它很容易让人们使用命令 graph2ppt() 来做到这一点并且可以很好地以矢量格式导出,而不是上面发布的其他答案中的位图,例如

install.packages("export")
library(export)
library(ggplot2)
qplot(Sepal.Length, Petal.Length, data = iris, color = Species,
size = Petal.Width, alpha = I(0.7))
graph2ppt(file="plots.pptx", width=6, height=5)

关于r - 在给定大小的 powerpoint 幻灯片中绘制 ggplot2 图 - R,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54236148/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com