Creating and saving multiple plots to Powerpoint

[This article was first published on HighlandR, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

At the NHS R conference we delivered a session on animating patient flow. This started with a single plot showing all patient movements, and then I demonstrated the ability to create a faceted plot.

But, with many different areas, and a small plot space, the faceted plot was a bit meh really.

So what else could we do?

How about creating individual plots for each ward area? And saving them into Powerpoint for onward distribution?

All the files you need to recreate this are on the repo.
If all goes well, you should create a series of images, and also save these to a powerpoint ready for onward distribution to the sort of folk who think spreadsheets are where it’s at.

<span class="c1"># some wards have very few movements, but how many?</span><span class="w">

</span><span class="n">source</span><span class="p">(</span><span class="s2">"1_setup.R"</span><span class="p">)</span><span class="w">
</span><span class="n">source</span><span class="p">(</span><span class="s2">"2_data_wrangling.R"</span><span class="p">)</span><span class="w">

</span><span class="n">library</span><span class="p">(</span><span class="n">officer</span><span class="p">)</span><span class="w">
</span><span class="n">library</span><span class="p">(</span><span class="n">magrittr</span><span class="p">)</span><span class="w">


</span><span class="n">setwd</span><span class="p">(</span><span class="n">here</span><span class="o">::</span><span class="n">here</span><span class="p">())</span><span class="w">

</span><span class="c1"># how many obs per group?</span><span class="w">

</span><span class="c1"># base R:</span><span class="w">
</span><span class="n">table</span><span class="p">(</span><span class="n">data</span><span class="o">$</span><span class="n">Ward_Dept</span><span class="p">)</span><span class="w">

</span><span class="c1"># succinct, but the output is not great..how it looks, structure etc</span><span class="w">


</span><span class="c1"># using dplyr we get a tibble, which is a more useful output</span><span class="w">

</span><span class="n">plot_data</span><span class="w"> </span><span class="o">%>%</span><span class="w"> 
  </span><span class="n">group_by</span><span class="p">(</span><span class="n">Ward_Dept</span><span class="p">)</span><span class="w"> </span><span class="o">%>%</span><span class="w"> 
  </span><span class="n">count</span><span class="p">()</span><span class="w"> </span><span class="o">%>%</span><span class="w"> 
  </span><span class="c1">#arrange in descending order</span><span class="w">
  </span><span class="n">arrange</span><span class="p">(</span><span class="n">desc</span><span class="p">(</span><span class="n">n</span><span class="p">))</span><span class="w">



</span><span class="c1">## create a list of distinct ward names</span><span class="w">

</span><span class="n">places</span><span class="w"> </span><span class="o"><-</span><span class="w"> </span><span class="n">plot_data</span><span class="w"> </span><span class="o">%>%</span><span class="w">  </span><span class="n">distinct</span><span class="p">(</span><span class="n">Ward_Dept</span><span class="p">)</span><span class="w"> </span><span class="o">%>%</span><span class="w"> 
  </span><span class="n">rename</span><span class="p">(</span><span class="n">Location</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">Ward_Dept</span><span class="p">)</span><span class="w">


</span><span class="c1">#create plot function </span><span class="w">

</span><span class="n">png_plot</span><span class="w"> </span><span class="o"><-</span><span class="w"> </span><span class="k">function</span><span class="p">(</span><span class="n">Location</span><span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="w">
  
  </span><span class="n">plot_colours</span><span class="w"> </span><span class="o"><-</span><span class="w"> </span><span class="nf">c</span><span class="p">(</span><span class="s2">"orangered1"</span><span class="p">,</span><span class="s2">"royalblue2"</span><span class="p">,</span><span class="s2">"grey60"</span><span class="p">)</span><span class="w">
  
  </span><span class="n">tempdf</span><span class="w"> </span><span class="o"><-</span><span class="w"> </span><span class="n">plot_data</span><span class="w"> </span><span class="o">%>%</span><span class="w"> 
    </span><span class="n">filter</span><span class="p">(</span><span class="n">Ward_Dept</span><span class="w"> </span><span class="o">==</span><span class="w"> </span><span class="n">Location</span><span class="p">)</span><span class="w"> 
  
  </span><span class="n">ggplot</span><span class="p">(</span><span class="n">plot_data</span><span class="p">,</span><span class="n">aes</span><span class="p">(</span><span class="n">Movement15</span><span class="p">,</span><span class="w"> </span><span class="n">Movement_15_SEQNO</span><span class="p">,</span><span class="n">colour</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">Movement_Type</span><span class="p">))</span><span class="w"> </span><span class="o">+</span><span class="w">
    </span><span class="n">geom_point</span><span class="p">(</span><span class="n">alpha</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="m">0</span><span class="p">)</span><span class="w"> </span><span class="o">+</span><span class="w">
    </span><span class="n">geom_point</span><span class="p">(</span><span class="n">data</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">tempdf</span><span class="p">,</span><span class="n">aes</span><span class="p">(</span><span class="n">Movement15</span><span class="p">,</span><span class="n">Movement_15_SEQNO</span><span class="p">,</span><span class="n">colour</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">Movement_Type</span><span class="p">),</span><span class="w"> </span><span class="n">na.rm</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="kc">FALSE</span><span class="p">)</span><span class="w"> </span><span class="o">+</span><span class="w">
    </span><span class="n">scale_colour_manual</span><span class="p">(</span><span class="n">values</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">plot_colours</span><span class="p">,</span><span class="n">drop</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="kc">FALSE</span><span class="p">)</span><span class="w"> </span><span class="o">+</span><span class="w">
    </span><span class="n">scale_x_datetime</span><span class="p">(</span><span class="n">date_labels</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">"%H:%M"</span><span class="p">,</span><span class="n">date_breaks</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">"3 hours"</span><span class="p">,</span><span class="w">
                     </span><span class="n">limits</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">lims</span><span class="p">,</span><span class="w">
                     </span><span class="n">timezone</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">"GMT"</span><span class="p">,</span><span class="w">
                     </span><span class="n">expand</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nf">c</span><span class="p">(</span><span class="m">0</span><span class="p">,</span><span class="m">0</span><span class="p">))</span><span class="w"> </span><span class="o">+</span><span class="w">
    </span><span class="n">scale_y_continuous</span><span class="p">(</span><span class="n">breaks</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">seq</span><span class="p">(</span><span class="m">-15</span><span class="p">,</span><span class="m">15</span><span class="p">,</span><span class="w"> </span><span class="n">by</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="m">5</span><span class="p">),</span><span class="w"> </span><span class="n">limits</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nf">c</span><span class="p">(</span><span class="m">-15</span><span class="p">,</span><span class="m">15</span><span class="p">))</span><span class="w"> </span><span class="o">+</span><span class="w">
    </span><span class="n">expand_limits</span><span class="p">(</span><span class="n">y</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nf">c</span><span class="p">(</span><span class="m">-15</span><span class="p">,</span><span class="w"> </span><span class="m">15</span><span class="p">))</span><span class="w"> </span><span class="o">+</span><span class="w">
    </span><span class="n">ggtitle</span><span class="p">(</span><span class="n">label</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">"Anytown General Hospital | Wednesday 3rd September 2014 00:00 to 23:59\n"</span><span class="p">,</span><span class="w">
            </span><span class="n">subtitle</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">paste0</span><span class="p">(</span><span class="n">Location</span><span class="p">,</span><span class="s2">" ARRIVALS, DEPARTURES AND TRANSFERS"</span><span class="p">))</span><span class="w"> </span><span class="o">+</span><span class="w">
    </span><span class="n">labs</span><span class="p">(</span><span class="n">x</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="kc">NULL</span><span class="p">,</span><span class="w"> </span><span class="n">y</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="kc">NULL</span><span class="p">,</span><span class="n">caption</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">"NHS-R conference"</span><span class="p">)</span><span class="w"> </span><span class="o">+</span><span class="w">
    </span><span class="n">theme_minimal</span><span class="p">(</span><span class="n">base_size</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="m">11</span><span class="p">)</span><span class="w"> </span><span class="o">+</span><span class="w">
    </span><span class="n">theme</span><span class="p">(</span><span class="n">legend.position</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">"bottom"</span><span class="p">)</span><span class="w"> </span><span class="o">+</span><span class="w">
    </span><span class="n">theme</span><span class="p">(</span><span class="n">panel.grid.minor</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">element_blank</span><span class="p">())</span><span class="w"> </span><span class="o">+</span><span class="w">
    </span><span class="n">theme</span><span class="p">(</span><span class="n">strip.text.y</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">element_text</span><span class="p">(</span><span class="n">angle</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="m">180</span><span class="p">))</span><span class="w"> </span><span class="o">+</span><span class="w">
    </span><span class="n">guides</span><span class="p">(</span><span class="n">color</span><span class="w"> </span><span class="o">=</span><span class="w">  </span><span class="n">guide_legend</span><span class="p">(</span><span class="s2">"Movement Type"</span><span class="p">))</span><span class="w">
  
  </span><span class="n">ggsave</span><span class="p">(</span><span class="n">filename</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">paste0</span><span class="p">(</span><span class="n">Location</span><span class="p">,</span><span class="s2">".png"</span><span class="p">),</span><span class="w">
         </span><span class="n">width</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="m">10</span><span class="p">,</span><span class="w"> </span><span class="n">height</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="m">8</span><span class="p">)</span><span class="w">  
  
</span><span class="p">}</span><span class="w">



</span><span class="c1"># create a folder to store .png files</span><span class="w">

</span><span class="n">dir.create</span><span class="p">(</span><span class="n">here</span><span class="o">::</span><span class="n">here</span><span class="p">(</span><span class="s2">"png"</span><span class="p">))</span><span class="w">

</span><span class="n">setwd</span><span class="p">(</span><span class="n">here</span><span class="o">::</span><span class="n">here</span><span class="p">(</span><span class="s2">"png"</span><span class="p">))</span><span class="w">

</span><span class="c1">## any errors here -  did you create the folder in the first place?</span><span class="w">


</span><span class="c1"># now use the walk function from purrr to create an image per location</span><span class="w">
</span><span class="n">walk</span><span class="p">(</span><span class="n">places</span><span class="o">$</span><span class="n">Location</span><span class="p">,</span><span class="n">png_plot</span><span class="p">)</span><span class="w">

</span><span class="c1">#check your ".png" folder</span><span class="w">

</span><span class="c1">#now copy a blank powerpoint template from home directory to current "png" directory</span><span class="w">
</span><span class="c1"># file.copy(where from, what, where to)</span><span class="w">
</span><span class="n">file.copy</span><span class="p">(</span><span class="n">file.path</span><span class="p">(</span><span class="n">here</span><span class="o">::</span><span class="n">here</span><span class="p">(),</span><span class="s2">"blank.pptx"</span><span class="p">),</span><span class="w"> </span><span class="n">getwd</span><span class="p">())</span><span class="w">


</span><span class="c1">############## automating powerpoint slides using officer ###############</span><span class="w">


</span><span class="c1"># Set a footer</span><span class="w">
</span><span class="n">set_ftr</span><span class="w"> </span><span class="o"><-</span><span class="w"> </span><span class="s2">"NHS_R Conference Oct 2018"</span><span class="w">
</span><span class="n">set_pres</span><span class="w"> </span><span class="o"><-</span><span class="w"> </span><span class="n">read_pptx</span><span class="p">(</span><span class="s2">"blank.pptx"</span><span class="p">)</span><span class="w"> </span><span class="o">%>%</span><span class="w"> </span><span class="c1"># Load template Add a slide</span><span class="w">
  </span><span class="n">add_slide</span><span class="p">(</span><span class="n">layout</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">"Title Slide"</span><span class="p">,</span><span class="w"> </span><span class="n">master</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">"Office Theme"</span><span class="p">)</span><span class="w"> </span><span class="o">%>%</span><span class="w"> </span><span class="c1"># Add some text to the title (ctrTitle)</span><span class="w">
  </span><span class="n">ph_with_text</span><span class="p">(</span><span class="n">type</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">"ctrTitle"</span><span class="p">,</span><span class="w"> </span><span class="n">str</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">"Drill Down to Individual Location"</span><span class="p">)</span><span class="w"> </span><span class="o">%>%</span><span class="w"> </span><span class="c1"># Add some text to the subtitle (subTitle)</span><span class="w">
  </span><span class="n">ph_with_text</span><span class="p">(</span><span class="n">type</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">"subTitle"</span><span class="p">,</span><span class="w"> </span><span class="n">str</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">"Individual Location Plots"</span><span class="p">)</span><span class="w"> </span><span class="o">%>%</span><span class="w"> 
  </span><span class="n">ph_with_text</span><span class="p">(</span><span class="n">type</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">"ftr"</span><span class="p">,</span><span class="w"> </span><span class="n">str</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">set_ftr</span><span class="p">)</span><span class="w">



</span><span class="n">slidef</span><span class="w"> </span><span class="o"><-</span><span class="w"> </span><span class="k">function</span><span class="p">(</span><span class="n">places</span><span class="p">,</span><span class="w"> </span><span class="n">pres</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">set_pres</span><span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="w">
  </span><span class="n">set_pres</span><span class="w"> </span><span class="o">%>%</span><span class="w"> 
    </span><span class="n">add_slide</span><span class="p">(</span><span class="n">layout</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">"Title and Content"</span><span class="p">,</span><span class="w"> </span><span class="n">master</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">"Office Theme"</span><span class="p">)</span><span class="w"> </span><span class="o">%>%</span><span class="w">
    </span><span class="n">ph_with_text</span><span class="p">(</span><span class="n">type</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">"ftr"</span><span class="p">,</span><span class="w"> </span><span class="n">str</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">set_ftr</span><span class="p">)</span><span class="w"> </span><span class="o">%>%</span><span class="w"> 
    </span><span class="n">ph_with_img</span><span class="p">(</span><span class="n">type</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">"body"</span><span class="p">,</span><span class="w"> </span><span class="n">index</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="m">1</span><span class="p">,</span><span class="w"> 
                </span><span class="n">src</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">paste0</span><span class="p">(</span><span class="n">places</span><span class="p">,</span><span class="w"> </span><span class="s2">".png"</span><span class="p">))</span><span class="w"> </span><span class="o">-></span><span class="w"> </span><span class="n">set_pres</span><span class="w">  </span><span class="c1"># get images </span><span class="w">
</span><span class="p">}</span><span class="w">



</span><span class="n">walk</span><span class="p">(</span><span class="n">places</span><span class="o">$</span><span class="n">Location</span><span class="p">,</span><span class="w"> </span><span class="n">slidef</span><span class="p">)</span><span class="w">
</span><span class="n">set_pres</span><span class="w"> </span><span class="o">%>%</span><span class="w"> </span><span class="n">print</span><span class="p">(</span><span class="n">target</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">"All Wards.pptx"</span><span class="p">)</span><span class="w"> </span><span class="o">%>%</span><span class="w"> </span><span class="nf">invisible</span><span class="p">()</span><span class="w">

</span><span class="c1">## hooray</span><span class="w">

</span><span class="c1"># move the powerpoints elsewhere, then delete them from current folder</span><span class="w">
</span><span class="n">filestomove</span><span class="w"> </span><span class="o"><-</span><span class="w"> </span><span class="nf">c</span><span class="p">(</span><span class="s2">"All Wards.pptx"</span><span class="p">,</span><span class="s2">"blank.pptx"</span><span class="p">)</span><span class="w">


</span><span class="n">file.copy</span><span class="p">(</span><span class="n">file.path</span><span class="p">(</span><span class="n">getwd</span><span class="p">(),</span><span class="n">filestomove</span><span class="p">),</span><span class="w"> </span><span class="n">here</span><span class="o">::</span><span class="n">here</span><span class="p">())</span><span class="w">


</span><span class="n">file.remove</span><span class="p">(</span><span class="n">filestomove</span><span class="p">)</span><span class="w">


</span><span class="c1">#make sure you are still in the png folder</span><span class="w">
</span><span class="n">getwd</span><span class="p">()</span><span class="w">

</span><span class="n">filenames</span><span class="w"> </span><span class="o"><-</span><span class="w"> </span><span class="n">dir</span><span class="p">()</span><span class="w">


</span><span class="n">library</span><span class="p">(</span><span class="n">gifski</span><span class="p">)</span><span class="w">
</span><span class="n">gifski</span><span class="p">(</span><span class="n">png_files</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">filenames</span><span class="p">,</span><span class="w"> </span><span class="n">gif_file</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">"Location_animation.gif"</span><span class="p">,</span><span class="w"> </span><span class="n">width</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="m">800</span><span class="p">,</span><span class="w"> </span><span class="n">height</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="m">600</span><span class="p">,</span><span class="w">
       </span><span class="n">delay</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="m">1</span><span class="p">,</span><span class="w"> </span><span class="n">loop</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="kc">TRUE</span><span class="p">,</span><span class="w"> </span><span class="n">progress</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="kc">TRUE</span><span class="p">)</span><span class="w">

</span><span class="n">utils</span><span class="o">::</span><span class="n">browseURL</span><span class="p">(</span><span class="s2">"Location_animation.gif"</span><span class="p">)</span><span class="w">

</span><span class="c1"># stick this in a powerpoint too?</span><span class="w">

</span><span class="n">file.copy</span><span class="p">(</span><span class="n">file.path</span><span class="p">(</span><span class="n">here</span><span class="o">::</span><span class="n">here</span><span class="p">(),</span><span class="s2">"blank.pptx"</span><span class="p">),</span><span class="w"> </span><span class="n">getwd</span><span class="p">())</span><span class="w">

</span><span class="c1"># Set a footer</span><span class="w">
</span><span class="n">set_ftr</span><span class="w"> </span><span class="o"><-</span><span class="w"> </span><span class="s2">"NHS_R Conference Oct 2018"</span><span class="w">
</span><span class="n">set_pres</span><span class="w"> </span><span class="o"><-</span><span class="w"> </span><span class="n">read_pptx</span><span class="p">(</span><span class="s2">"blank.pptx"</span><span class="p">)</span><span class="w"> </span><span class="o">%>%</span><span class="w"> </span><span class="c1"># Load template Add a slide</span><span class="w">
  </span><span class="n">add_slide</span><span class="p">(</span><span class="n">layout</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">"Title Slide"</span><span class="p">,</span><span class="w"> </span><span class="n">master</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">"Office Theme"</span><span class="p">)</span><span class="w"> </span><span class="o">%>%</span><span class="w"> </span><span class="c1"># Add some text to the title (ctrTitle)</span><span class="w">
  </span><span class="n">ph_with_text</span><span class="p">(</span><span class="n">type</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">"ctrTitle"</span><span class="p">,</span><span class="w"> </span><span class="n">str</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">"Individual Location Animation"</span><span class="p">)</span><span class="w"> </span><span class="o">%>%</span><span class="w"> </span><span class="c1"># Add some text to the subtitle (subTitle)</span><span class="w">
  </span><span class="n">ph_with_text</span><span class="p">(</span><span class="n">type</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">"subTitle"</span><span class="p">,</span><span class="w"> </span><span class="n">str</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">"Individual Location Plots gif"</span><span class="p">)</span><span class="w"> </span><span class="o">%>%</span><span class="w"> 
  </span><span class="n">ph_with_text</span><span class="p">(</span><span class="n">type</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">"ftr"</span><span class="p">,</span><span class="w"> </span><span class="n">str</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">set_ftr</span><span class="p">)</span><span class="w">




</span><span class="n">set_pres</span><span class="w"> </span><span class="o">%>%</span><span class="w"> 
  </span><span class="n">add_slide</span><span class="p">(</span><span class="n">layout</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">"Title and Content"</span><span class="p">,</span><span class="w"> </span><span class="n">master</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">"Office Theme"</span><span class="p">)</span><span class="w"> </span><span class="o">%>%</span><span class="w">
  </span><span class="n">ph_with_text</span><span class="p">(</span><span class="n">type</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">"ftr"</span><span class="p">,</span><span class="w"> </span><span class="n">str</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">set_ftr</span><span class="p">)</span><span class="w"> </span><span class="o">%>%</span><span class="w"> 
  </span><span class="n">ph_with_img</span><span class="p">(</span><span class="n">type</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">"body"</span><span class="p">,</span><span class="w"> </span><span class="n">index</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="m">1</span><span class="p">,</span><span class="w"> 
              </span><span class="n">src</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">"Location_animation.gif"</span><span class="p">)</span><span class="w"> </span><span class="o">-></span><span class="w"> </span><span class="n">set_pres</span><span class="w">  </span><span class="c1"># get images </span><span class="w">

</span><span class="n">set_pres</span><span class="w"> </span><span class="o">%>%</span><span class="w"> </span><span class="n">print</span><span class="p">(</span><span class="n">target</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">"Animation.pptx"</span><span class="p">)</span><span class="w"> </span><span class="o">%>%</span><span class="w"> </span><span class="nf">invisible</span><span class="p">()</span><span class="w">


</span><span class="c1"># move the powerpoints to the root of the folder, then delete them from current folder</span><span class="w">
</span><span class="n">filestomove</span><span class="w"> </span><span class="o"><-</span><span class="w"> </span><span class="nf">c</span><span class="p">(</span><span class="s2">"Animation.pptx"</span><span class="p">,</span><span class="s2">"Location_animation.gif"</span><span class="p">,</span><span class="s2">"blank.pptx"</span><span class="p">)</span><span class="w">


</span><span class="n">file.copy</span><span class="p">(</span><span class="n">file.path</span><span class="p">(</span><span class="n">getwd</span><span class="p">(),</span><span class="n">filestomove</span><span class="p">),</span><span class="w"> </span><span class="n">here</span><span class="o">::</span><span class="n">here</span><span class="p">())</span><span class="w">
</span><span class="n">file.remove</span><span class="p">(</span><span class="n">filestomove</span><span class="p">)</span><span class="w">

</span><span class="c1">#go back home</span><span class="w">
</span><span class="n">setwd</span><span class="p">(</span><span class="n">here</span><span class="o">::</span><span class="n">here</span><span class="p">())</span><span class="w">

</span>

There you have it.
Credit to Len Keifer, who’s code I borrowed liberally (found it, pinched it) in order to create the slides in powerpoint.
These techniques have saved me a lot of time each month – with a small bit of setup time, regular reporting can be automated, giving you time to work on the harder stuff.

To leave a comment for the author, please follow the link and comment on their blog: HighlandR.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)