use*_*169 6 powerpoint r reporters
我有一个pptx格式的演示文稿,我需要经常使用R脚本生成的图表进行更新.我想自动更换图表,而不必在屏幕之间复制和粘贴很多次.我一直在使用ReporteRs包,看起来很有希望,但我无法弄清楚如何简单地替换演示文稿中已有的图表.ReporteRs上的所有文档都表明您必须添加新幻灯片,然后将图表放在新幻灯片上.有没有办法说'删除幻灯片7上的图表并将其替换为图表XXX?' ReporteRs是最好的方案吗?
尝试:
library(DescTools)
# create a new PP instance
pp <- GetNewPP()
# create your plt and insert into pp
barplot(1:5)
pic <- PpPlot(width=10, height=5, pp=pp)
# add a new slide
PpAddSlide()
# new plot on new slide, just to make it difficult to go back
barplot(10:5)
pic2 <- PpPlot(width=10, height=5, pp=pp)
# get a collection of slides
slides <- pp[["ActivePresentation"]][["Slides"]]
# maybe convenient to go back to slide 1
slides$Item(1)$Select()
# get a handle to slide 1
slide1 <- slides$Item(1)
# get handle to any pic on the slide
pic1 <- slide1[["Shapes"]]$Item(1)
# delete it
pic1$Delete()
# create and insert a new one
barplot(rep(1,5), col="red")
PpPlot(width=10, height=5, pp=pp)
Run Code Online (Sandbox Code Playgroud)