生成电源点时更改绘图比例或 table
Changing the scale of a plot or table when generating a power point
我希望在生成图表时能够选择插入到我的 powerpoint 中的图表的尺寸。我意识到我可以简单地将它们保存为一个单独的文件然后插入它们。但我更愿意在创建时将它们插入幻灯片时能够操纵它们。无论是通过在插入前更改绘图尺寸还是更改幻灯片的边界框尺寸。
我已经做了一些测试:
"use_loc_size = F" 在 ph_with 中似乎只适用于图像,据我从我所做的测试中可以看出。
改变像素质量确实会稍微改变比例,但如果我触摸它,标签和图表似乎会以非常不同的方式变化(标签越大,像素数越高,而图表越小,反之亦然当我减少像素数时)
示例代码:
library(flextable)
library(rvg)
library(officer)
library(ggplot2)
path_out <- "."
# prep ggplot
p1 <- iris %>%
ggplot() +
geom_point(aes(Sepal.Length,Petal.Length,color = Species), size = 3) +
theme_minimal()
# prep editable graph (rvg)
p2 <- dml(ggobj = p1)
my_pres <- read_pptx() %>%
#slide 1
add_slide(layout = "Title and Content", master = "Office Theme") %>%
ph_with(value = p1, location = ph_location_type("body", width = 2, height = 13)) %>%
#slide 2
add_slide() %>%
ph_with(value = p2, location = ph_location_type("body"), width = 6, height = 6) %>%
print(target = file.path(path_out,"example_v1.pptx"))
如果您想在不使用占位符属性的情况下从 R 定义大小,可以使用 ph_location
并指定宽度、高度和左上角位置:
library(flextable)
library(rvg)
library(officer)
library(ggplot2)
library(magrittr)
path_out <- "."
# prep ggplot
p1 <- iris %>%
ggplot() +
geom_point(aes(Sepal.Length,Petal.Length,color = Species), size = 3) +
theme_minimal()
# prep editable graph (rvg)
p2 <- dml(ggobj = p1)
my_pres <- read_pptx() %>%
#slide 1
add_slide(layout = "Title and Content", master = "Office Theme") %>%
ph_with(value = p1, location = ph_location("body", left = 1, top = 1, width = 5, height = 5)) %>%
#slide 2
add_slide() %>%
ph_with(value = p2, location = ph_location("body", left = 1, top = 1, width = 5, height = 5)) %>%
print(target = file.path(path_out,"example_v1.pptx"))
我希望在生成图表时能够选择插入到我的 powerpoint 中的图表的尺寸。我意识到我可以简单地将它们保存为一个单独的文件然后插入它们。但我更愿意在创建时将它们插入幻灯片时能够操纵它们。无论是通过在插入前更改绘图尺寸还是更改幻灯片的边界框尺寸。
我已经做了一些测试:
"use_loc_size = F" 在 ph_with 中似乎只适用于图像,据我从我所做的测试中可以看出。
改变像素质量确实会稍微改变比例,但如果我触摸它,标签和图表似乎会以非常不同的方式变化(标签越大,像素数越高,而图表越小,反之亦然当我减少像素数时)
示例代码:
library(flextable)
library(rvg)
library(officer)
library(ggplot2)
path_out <- "."
# prep ggplot
p1 <- iris %>%
ggplot() +
geom_point(aes(Sepal.Length,Petal.Length,color = Species), size = 3) +
theme_minimal()
# prep editable graph (rvg)
p2 <- dml(ggobj = p1)
my_pres <- read_pptx() %>%
#slide 1
add_slide(layout = "Title and Content", master = "Office Theme") %>%
ph_with(value = p1, location = ph_location_type("body", width = 2, height = 13)) %>%
#slide 2
add_slide() %>%
ph_with(value = p2, location = ph_location_type("body"), width = 6, height = 6) %>%
print(target = file.path(path_out,"example_v1.pptx"))
如果您想在不使用占位符属性的情况下从 R 定义大小,可以使用 ph_location
并指定宽度、高度和左上角位置:
library(flextable)
library(rvg)
library(officer)
library(ggplot2)
library(magrittr)
path_out <- "."
# prep ggplot
p1 <- iris %>%
ggplot() +
geom_point(aes(Sepal.Length,Petal.Length,color = Species), size = 3) +
theme_minimal()
# prep editable graph (rvg)
p2 <- dml(ggobj = p1)
my_pres <- read_pptx() %>%
#slide 1
add_slide(layout = "Title and Content", master = "Office Theme") %>%
ph_with(value = p1, location = ph_location("body", left = 1, top = 1, width = 5, height = 5)) %>%
#slide 2
add_slide() %>%
ph_with(value = p2, location = ph_location("body", left = 1, top = 1, width = 5, height = 5)) %>%
print(target = file.path(path_out,"example_v1.pptx"))