I have the following piece of code where I: 1) populate a data frame and its summary into PPT using officer package 2) Calculate summary from data frame using table function
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")
I have 2 questions here which I am unable to solve and need help:
1) I am unable to change the font and font size of the output in PPT. Can someone help me here 2) When I calculate the dataframe "overview.df" from "table1", sometimes the output contains "Yes, "No" and "Transit" for which the above code works. But sometimes, the input data frame only contains "Yes" and "No" for which my code fails. Hence I would like a generic code to replace the following lines:
table1 <- table(df1$Country, df1$State)
overview.df <- data.frame(Country = rownames(table1),
Not.Delivered =table1[,1],
In.Transit = table1[,2],
Delivered = table1[,3])
Thanks all in advance! Awaiting your reply.