我想將我的 R 餅圖保存到 pptx,所以我設法到達了代碼的最后一步。
df <- data.frame(Type = c('x','y'),Count = c(177,41))
ggplt <- ggplot(df, aes(x = "", y = Count, fill = Type))
geom_col(width = 1)
scale_fill_manual(values = c("red", "yellow"))
coord_polar("y")
geom_text(aes(label = paste0("Count=",Count)), position = position_stack(vjust = 0.5))
labs(title = "Employees Count")
myppt <- read_pptx()
myppt <- add_slide(myppt,layout="Two Content",master = "Office Theme")
myppt <- ph_with(myppt,type = "body",value = ggplt,location = ph_location_left())
在運行最后一條陳述句時,ph_with()我收到錯誤訊息:
Error in match.arg(type) :
'arg' should be one of “windows”, “cairo”, “cairo-png”
如果有人能告訴我在哪里搞砸了,我將不勝感激!!
uj5u.com熱心網友回復:
問題是您使用type="body"了ph_withwhich 但是沒有type引數。因此,type引數通過傳遞給引起神秘錯誤...的png()函式。
這就是說,您可以通過洗掉來實作您想要的結果type="body":
library(officer)
library(ggplot2)
df <- data.frame(Type = c('x','y'),Count = c(177,41))
ggplt <- ggplot(df, aes(x = "", y = Count, fill = Type))
geom_col(width = 1)
scale_fill_manual(values = c("red", "yellow"))
coord_polar("y")
geom_text(aes(label = paste0("Count=",Count)), position = position_stack(vjust = 0.5))
labs(title = "Employees Count")
myppt <- read_pptx()
myppt <- add_slide(myppt,layout="Two Content",master = "Office Theme")
myppt <- ph_with(myppt, value = ggplt, location = ph_location_left())
print(myppt, "foo.pptx")

uj5u.com熱心網友回復:
你應該看看rmarkdown。有了它,您可以編織(轉換)您的 r 檔案或報告為 pptx 檔案。要訪問它,請在 rstudio 中單擊新檔案,然后按新降價檔案。
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/384673.html
