【发布时间】:2020-05-27 13:54:00
【问题描述】:
我有以下代码: 1)使用officer包将数据框及其摘要填充到PPT中 2) 使用表函数从数据框中计算摘要
library(officer)
df1 <- data.frame(
Country = c("France", "England", "India", "America", "England", "India"),
City = c("Paris", "London", "Mumbai", "Los Angeles", "Surrey", "Chennai"),
Order_No = c("1", "2", "3", "4", "5", "6"),
State = c("Yes", "No", "Yes", "No", "Yes", "Transit"),
stringsAsFactors = FALSE
)
my_pres <- read_pptx()
my_pres <- add_slide(my_pres, layout = "Title and Content", master = "Office Theme")
my_pres <- ph_with(my_pres, value = "heading", location = ph_location_type(type = "title"))
my_pres <- ph_with(my_pres, value = df1, location = ph_location_type(type = "body"), header = TRUE)
print(my_pres, target = "first_example.pptx")
table1 <- table(df1$Country, df1$State)
overview.df <- data.frame(Country = rownames(table1),
Not.Delivered =table1[,1],
In.Transit = table1[,2],
Delivered = table1[,3])
my_pres <- add_slide(my_pres, layout = "Title and Content", master = "Office Theme")
my_pres <- ph_with(my_pres, value = "Summary", location = ph_location_type(type = "title"))
my_pres <- ph_with(my_pres, value = overview.df, location = ph_location_type(type = "body"), header = TRUE)
print(my_pres, target = "first_example.pptx")
我有 2 个问题无法解决,需要帮助:
1) 我无法更改 PPT 中输出的字体和字号。有人可以在这里帮助我吗 2)当我从“table1”计算数据帧“overview.df”时,有时输出包含上述代码适用的“是”、“否”和“过境”。但有时,输入数据帧只包含“是”和我的代码失败的“否”。因此我想要一个通用代码来替换以下几行:
table1 <- table(df1$Country, df1$State)
overview.df <- data.frame(Country = rownames(table1),
Not.Delivered =table1[,1],
In.Transit = table1[,2],
Delivered = table1[,3])
提前谢谢大家!等待您的回复。
【问题讨论】:
-
@shome 感谢您的链接;但它没有提到如何减小要导出到幻灯片的数据框的字体大小。你能帮我提供示例代码吗?
-
@ruser..检查字体相关设置的第一个答案。我正在尝试输入一些代码。