ph_与R上的_vg和GG绘图
我可以使用以下代码使用ggplot创建所需的图表:ph_与R上的_vg和GG绘图,r,ggplot2,officer,R,Ggplot2,Officer,我可以使用以下代码使用ggplot创建所需的图表: ggplot(data, aes(x=as.Date(data$Date, "%d/%m/%Y"), y=items)) + geom_col(fill="#00cccc") 但是,当我在完整代码中使用它时,会出现一个错误,显示为“StartTag:invalid element name[68]” 我的压力% #02-幻灯片 添加幻灯片(layout=“Title with Subtitle and Content”,master=
ggplot(data, aes(x=as.Date(data$Date, "%d/%m/%Y"), y=items)) + geom_col(fill="#00cccc")
但是,当我在完整代码中使用它时,会出现一个错误,显示为“StartTag:invalid element name[68]”
我的压力%
#02-幻灯片
添加幻灯片(layout=“Title with Subtitle and Content”,master=“MySlides2016”)%>%
#02-标题
带有文字的PHU(type=“title”,str=“按日项目”)%>%
#02-图表
ph_和vg_位于(代码=ggplot(数据,aes(x=截止日期(数据$Date,“%d/%m/%Y”),Y=项目))+geom_col(fill=“#00cccc”),左=1,顶=2,宽=6,高=4)
如果您阅读了可用的文档,它说明您必须在函数ph\u中使用打印(您的_ggplot\u对象)
,并在_vg\u处使用
,因此您可以执行以下操作:
library("officer")
library("rvg")
library("magrittr")
library("ggplot2")
gg <- ggplot(mtcars, aes(x = mpg , y = wt, colour = qsec)) + geom_point() + theme_minimal()
my_pres<-
# Load template
read_pptx() %>%
# 02 - SLIDE
add_slide(layout = "Title and Content", master = "Office Theme") %>%
# 02 - Title
ph_with_text(type = "title", str = "Items by Day") %>%
# 02 - Chart
ph_with_vg_at(code = print(gg),left = 1, top = 2, width = 6, height = 4)
# Save
tmp <- tempfile(fileext = ".pptx")
print(my_pres, target = tmp)
# Open
browseURL(tmp)
图书馆(“官员”)
图书馆(“rvg”)
图书馆(“magrittr”)
图书馆(“ggplot2”)
gg%
#02-标题
带有文字的PHU(type=“title”,str=“按日项目”)%>%
#02-图表
ph_和_vg_位于(代码=打印(gg),左侧=1,顶部=2,宽度=6,高度=4)
#拯救
tmp
library("officer")
library("rvg")
library("magrittr")
library("ggplot2")
gg <- ggplot(mtcars, aes(x = mpg , y = wt, colour = qsec)) + geom_point() + theme_minimal()
my_pres<-
# Load template
read_pptx() %>%
# 02 - SLIDE
add_slide(layout = "Title and Content", master = "Office Theme") %>%
# 02 - Title
ph_with_text(type = "title", str = "Items by Day") %>%
# 02 - Chart
ph_with_vg_at(code = print(gg),left = 1, top = 2, width = 6, height = 4)
# Save
tmp <- tempfile(fileext = ".pptx")
print(my_pres, target = tmp)
# Open
browseURL(tmp)