Logo

Rendering PowerPoint Presentations with the RStudio IDE

Avatar

Getting Started

To create a PowerPoint presentation, open a new R Markdown PowerPoint presentation or specify powerpoint_presentation as an output format in the YAML header.

New File > R Markdown > Presentation > PowerPoint

powerpoint presentations with r markdown

When you knit an R Markdown document, RStudio renders your document in the PowerPoint output format. If you are using RStudio Desktop, your PowerPoint presentation will automatically open and take you back to the last slide you were viewing. If you are using RStudio Workbench (previously RStudio Server Pro) or RStudio Server Open Source, you will be prompted to download the PowerPoint presentation file.

powerpoint presentations with r markdown

You can also render files programmatically from the R console.

In some cases, you might want to make manual adjustments to your PowerPoint presentation after you render it. Fortunately, markdown elements – such as titles, text, code, and tables – are rendered natively in PowerPoint. Manually changing the slide size or design after rendering will automatically change these elements to match the new style.

Markdown Features

You can generate most elements supported by Pandoc’s Markdown with the PowerPoint output including: Inline formatting; lists; LaTeX math expressions/equations; images; hyperlinks; block quotations; and more. Here are some common elements supported in PowerPoint (for a complete list see the R Markdown Reference ).

Additionally, the PowerPoint output format also supports these handy features:

Images and tables

Speaker notes.

Images will be scaled automatically to fit the slide. You can render images from file or from the web. Captions will render below the image. You can add a link to the caption or to the image itself.

Tables render natively in PowerPoint and pick up the style defined by the reference template .

You can use the the Two Content layout to put material in side by side columns. For example, you can put text next to an image on the same slide. To use the Two Content layout, nest two div containers of class column inside one div container of class columns .

You can add speaker notes to slides. Speaker notes support limited formats such as bold, italics, and lists. Speaker notes, of course, will be available in handouts and in presenter view.

Images and tables will always be placed on new slides. The only elements that can coexist with an image or table on a slide are the slide header and caption.

The size and design of PowerPoint presentations are determined by the reference template. Pandoc ships with a default PowerPoint template that contains a blank presentation in the standard (4:3) size. If you want to change the size or design of a PowerPoint presentation, you should use a custom template. Reference a template with the reference_doc option in the YAML header.

The template should contain the following four layouts as its first four layouts. Any template included with a recent install of PowerPoint (either with .pptx or .potx extension) should work, as will most templates derived from these. Markdown headers and content will map to slide layouts and placeholders according to the rules in Structuring the Presentation .

  • Title . Has placeholders for a title and a subtitle. Used for information in the YAML header.

powerpoint presentations with r markdown

  • Title and Content . Has placeholders for title and content. Used for headers at the slide level .

powerpoint presentations with r markdown

  • Section Header . Has a placeholder for a section header – content will not render on this layout. Used for headers above the slide level .

powerpoint presentations with r markdown

  • Two Content . Has placeholders for title and two content. Used for headers at the slide level with content in columns .

powerpoint presentations with r markdown

Structuring the Presentation

PowerPoint presentations have a hierarchy of title, section, and content slides whereas markdown documents have a hierarchy of headers and content. In order to structure a PowerPoint presentation, Pandoc needs to determine which markdown header level should be used for the PowerPoint slide level. For example, the markdown header ## Introduction might map to a section slide, while ### Details might map to a content slide.

By default, Pandoc sets the slide level to the highest header level in the hierarchy that is followed immediately by markdown content somewhere in the document. Once Pandoc determines the slide level, the markdown document is carved up into slides according the the following rules:

  • Headers at the slide level always starts a new slide
  • Headers above the slide level in the hierarchy create section headers
  • Headers below the slide level in the hierarchy create headers within a slide
  • A horizontal rule always starts a new slide
  • A title page is constructed automatically from the document’s title (i.e. YAML) block

The document above creates a presentation with four slides. The default slide level is 3 because the level 3 header is the first to be followed by content. You can override the default slide level by setting the slide_level option in the YAML header. Note: If you do not want to structure your slides into sections, you can just use level 1 headers to create all your slides.

  • R Code Chunks

R Code Chunks can be used as a means to render R output into documents or to simply display code for illustration. Source code will render with syntax highlighting inline with other markdown text in your document. You may choose to remove source code from your PowerPoint presentation by setting echo=FALSE in the code chunk options.

Table output

By default data frames and matrices are output as they would be in the R terminal (in a monospaced font). However, if you prefer that data be displayed as a PowerPoint table you can use the knitr::kable function. Table output from kable will assume the table design of whatever template you use.

Plot output

R code chunks can also be used to render plots. Images will be scaled automatically to fit the slide. You can change image size with fig.width and fig.height code chunk options.

You can capture HTML Widgets and Shiny apps by installing the webshot package and phantomjs . The webshot package will automatically take a screenshot of an interactive HTML Widget and insert it into your presentation. The knitr::include_app function will use webshot to embed a screenshot of a Shiny application that links viewers to a live application hosted on RStudio Connect, Shiny Server, or Shinyapps.io.

These code chunk options can be especially useful when rendering PowerPoint output.

  • echo . Control R source code in the output file. Set to FALSE if you do not want your source code included in your PowerPoint presentation.
  • cache . Save time by caching plots and other output. If document rendering becomes time consuming due to long computations or plots that are expensive to generate you can use knitr caching to improve performance.
  • screenshot.opts . Delay a webshot capture. An arbitrary URL may take a long time to load. You can increase the delay in order to give apps enough time to load before taking a webshot.
  • fig.width and fig.height . Size a plot. This should be numeric in inches. Default is 7.
  • fig.cap . Add a caption to an image. Captions will render below the image.

In this example the code chunk will wait one second for an app to load, resize the width to 15 inches, and cache the image for later use.

Getting Help

Click here for a list of examples. Submit PowerPoint issues to rmarkdown/issues . For more details, see these guides:

  • Troubleshooting PowerPoint Output
  • Markdown Basics
  • Pandoc Markdown
  • Chunk Options
  • Pandoc User’s Guide

How To Make A PowerPoint Presentation Using R Markdown

powerpoint presentations with r markdown

PowerPoint is the most recognized presentation-making software, but it isn’t for everyone. Some may find it packed with unnecessary features, and to some extent that's true. Microsoft updates it regularly and invents things you never even knew you needed. If you’re a programmer at heart, you likely value simplicity. That’s where this article comes in. We’ll ditch PowerPoint and make presentations in a way you didn’t know was possible. After reading, you’ll know how to make an entire editable PowerPoint presentation using only R Markdown. <blockquote><strong>Interested in a real-world use case? <a href="https://appsilon.com/gxp-compliance-in-pharma-made-easier-good-documentation-practices-with-r-markdown-and-officedown/" target="_blank" rel="noopener noreferrer">Here’s how we applied R Markdown in Pharma</a>.</strong></blockquote> Table of contents: <ul><li><a href="#getting-started">Getting Started</a></li><li><a href="#basics">What Can You Do With Markdown?</a></li><li><a href="#advanced">Images, Tables, and Custom Layout</a></li><li><a href="#style">How to Style Your R Markdown Presentation</a></li><li><a href="#conclusion">Conclusion</a></li></ul> <hr /> <h2 id="getting-started">R Markdown PowerPoint Presentation - Getting Started</h2> We assume you have R and RStudio installed. Once in RStudio, go to <em>File</em> - <em>New File</em> - <em>R Markdown</em>. A window like the one below should appear: <img class="size-full wp-image-12097" src="https://webflow-prod-assets.s3.amazonaws.com/6525256482c9e9a06c7a9d3c%2F65b01ee7832c47d67312b3e1_creating-new-r-markdown-powerpoint-presentaiton.webp" alt="Image 1 - Creating a new R Markdown PowerPoint Presentation" width="2564" height="1758" /> Image 1 - Creating a new R Markdown PowerPoint Presentation Give your presentation a title and optionally specify the author. Also, make sure to select <em>PowerPoint</em> as the default output format. R will ask you to install a couple of dependencies if this is your first time working with R Markdown. After clicking on OK you’ll see a default R Markdown PowerPoint presentation code: <img class="size-full wp-image-12099" src="https://webflow-prod-assets.s3.amazonaws.com/6525256482c9e9a06c7a9d3c%2F65b01ee892a26c843b62e764_Default-presentation-template.webp" alt="Image 2 - Default presentation template" width="2564" height="1758" /> Image 2 - Default presentation template That’s great, but how can you “compile” it? Well, easily! Click on the <strong>Knit dropdown</strong> and choose the <em>Knit to PowerPoint</em> option: <img class="size-full wp-image-12107" src="https://webflow-prod-assets.s3.amazonaws.com/6525256482c9e9a06c7a9d3c%2F65b01eea48b83fcd2e55b400_How-to-run-R-Markdown-PowerPoint-presentation.webp" alt="Image 3 - How to run R Markdown PowerPoint presentation" width="2564" height="1758" /> Image 3 - How to run R Markdown PowerPoint presentation That’s it! A PowerPoint presentation will be knitted and opened after a couple of seconds. Here’s what it looks like: <img class="size-full wp-image-12105" src="https://webflow-prod-assets.s3.amazonaws.com/6525256482c9e9a06c7a9d3c%2F65b01eea2a228de4b21e9ac2_First-rendered-presentation.gif" alt="Image 4 - First rendered presentation" width="1314" height="898" /> Image 4 - First rendered presentation It’s a strong start but definitely needs work. I'll show you how to spice it up in the sections below. First, we’ll explore what can you actually do with Markdown. <h2 id="basics">What Can You Do With Markdown?</h2> Markdown is a free-to-use markup language used to format plain text. It’s popular among developers and technical writers because it provides you with everything you need and nothing else. We’ll now explore what can you do with R Markdown, and how you can do it. You’ll learn how to: <ul><li><strong>Style the text</strong> - Use italics, bold, strikeout, subscript, superscript, small caps, and verbatim.</li><li><strong>Lists</strong> - Ordered and unordered.</li><li><strong>Links</strong> - Embed URLs to external websites.</li><li><strong>Quotes</strong> - Special indentation for your text.</li><li><strong>Equations</strong> - Does LaTeX ring a bell? You can use it in Markdown.</li></ul> We’ll also cover more advanced Markdown functionality, but these are enough for one section. Use the following code to declare two slides with all mentioned Markdown functionalities: <script src="https://gist.github.com/darioappsilon/b2da95cfb87db52c2a49ba4ea3bb150a.js"></script> Your R Markdown file should look like this: <img class="size-full wp-image-12103" src="https://webflow-prod-assets.s3.amazonaws.com/6525256482c9e9a06c7a9d3c%2F65b01eeb6bb6e6a6629bfa2b_Exploring-Markdown-options.webp" alt="Image 5 - Exploring Markdown options" width="2564" height="1758" /> Image 5 - Exploring Markdown options And once again, use <em>Knit to PowerPoint</em> option to export the PPTX: <img class="size-full wp-image-12109" src="https://webflow-prod-assets.s3.amazonaws.com/6525256482c9e9a06c7a9d3c%2F65b01eec9506383404c4ec25_Rendered-markdown-presentation.gif" alt="Image 6 - Rendered markdown presentation" width="1314" height="898" /> Image 6 - Rendered markdown presentation The R Markdown PowerPoint presentation still looks rough around the edges, but we’ll address the visuals soon. Before we do that, let’s go over a couple of “advanced” Markdown elements, and how to get the most out of them. <blockquote><strong>Want to include your Bar Plots in your presentation? Follow these <a href="https://appsilon.com/data-visualization-best-practices-bar-plots/" target="_blank" rel="noopener noreferrer">Data Visualization Best Practices</a>.</strong></blockquote> <h2 id="advanced">Adding Images, Tables, and Custom Layouts to an R Markdown PowerPoint Presentation</h2> A presentation without images and tables is, well, boring. Also, most presentations make use of multiple layouts. For example, there are scenarios where a two-column layout is preferred. You’ll learn how to use it in this section. The code snippet below implements the following: <ul><li><strong>1st Slide</strong> - Loads a dog image from <a href="https://unsplash.com/photos/UinXDJCcqeY" target="_blank" rel="noopener noreferrer">Unsplash</a> and adds a caption to it.</li><li><strong>2nd Slide</strong> - Shows a table representing a subset from the <a href="https://gist.github.com/netj/8836201" target="_blank" rel="noopener noreferrer">Iris dataset</a>.</li><li><strong>3rd Slide</strong> - Implements a two-column layout.</li></ul> <script src="https://gist.github.com/darioappsilon/37a7b72b33753d95fa4553f0c968dd98.js"></script> This time, you won’t see any rendered output in the R Markdown file: <img class="size-full wp-image-12095" src="https://webflow-prod-assets.s3.amazonaws.com/6525256482c9e9a06c7a9d3c%2F65b01eed00b05468d71b8f4e_Adding-images-tables-and-custom-layouts.webp" alt="Image 7 - Adding images, tables, and custom layouts" width="2564" height="1758" /> Image 7 - Adding images, tables, and custom layouts Here’s what the final PPTX looks like: <img class="size-full wp-image-12111" src="https://webflow-prod-assets.s3.amazonaws.com/6525256482c9e9a06c7a9d3c%2F65b01eefe6755ca41b304f53_Rendered-Powerpoint-presentation.gif" alt="Image 8 - Rendered Powerpoint presentation" width="1314" height="898" /> Image 8 - Rendered Powerpoint presentation You now know the basics of R Markdown - just enough to place any type of content into your R Markdown PowerPoint presentations. But how can you make the slideshow visually appealing? That’s what we’ll explore next. <h2 id="style">How to Style Your R Markdown PowerPoint Presentation</h2> The default PPTX layout is, well, default, and doesn’t look attractive at all. To change it, you’ll first have to create a blank PowerPoint presentation and open the Slide Master (<em>View - Slide Master</em>). Once inside, tweak it as you normally would when styling a PPTX file. <blockquote><strong>Excel is good, but not great. Check out our <a href="https://appsilon.com/excel-is-obsolete-here-are-the-top-2-alternatives-from-r-and-python/" target="_blank" rel="noopener noreferrer">top alternatives from R and Python</a>. </strong></blockquote> We’ll only change the theme, just to keep things simple: <img class="size-full wp-image-12101" src="https://webflow-prod-assets.s3.amazonaws.com/6525256482c9e9a06c7a9d3c%2F65b01ef20a2ba062e1ba27da_Editing-the-slide-master.webp" alt="Image 9 - Editing the slide master" width="3100" height="2024" /> Image 9 - Editing the slide master You’re free to take your time here and add custom graphics, fonts, and other visual elements. Once done, <strong>save the PPTX file right where your .Rmd file is</strong>: <img class="size-full wp-image-12115" src="https://webflow-prod-assets.s3.amazonaws.com/6525256482c9e9a06c7a9d3c%2F65b01ef40fc7bbb4c493e2d2_Saving-PowerPoint-template.webp" alt="Image 10 - Saving PowerPoint template" width="3424" height="2024" /> Image 10 - Saving PowerPoint template You can save it elsewhere, but it’s a good practice to keep the PowerPoint template and R Markdown file in the same directory. To use the template, you’ll only have to modify the header of the R Markdown file: <script src="https://gist.github.com/darioappsilon/f1b601dd3efaf3faa2e21ea06cf9c475.js"></script> That’s why we saved the PPTX template in the same directory. There’s no need to think about the path. Everything else in the Rmd file remains the same. Knit the PowerPoint presentation to verify the template was used: <img class="size-full wp-image-12113" src="https://webflow-prod-assets.s3.amazonaws.com/6525256482c9e9a06c7a9d3c%2F65b01ef4385c8d506b9c0ed3_Rendered-presentation-with-a-custom-template.gif" alt="Image 11 - Rendered presentation with a custom template" width="1314" height="898" /> Image 11 - Rendered presentation with a custom template And would you look at that - a custom PowerPoint template was successfully applied to our R Markdown PowerPoint presentation. We won’t dive into more advanced use cases today, as this alone is enough to cover what most programmers and tech users need. But if you'd like to learn about more advanced uses, let us know. <h2 id="conclusion">Conclusion</h2> PowerPoint isn’t for everyone, just like MS Word. If you know Markdown, you can write and edit text documents much faster than in a traditional word processor. What makes things even better is its shareability, as most online writing platforms understand Markdown. R Markdown is by no means a replacement for dedicated office suites, so keep that in mind. It might be a decent alternative if you need to automate slide production, simply don’t want to use PowerPoint, or if you don’t need all the functionalities it offers. To further drive the point home, we recommend the following homework tasks: <ul><li>Try to embed a YouTube video or a GIF. Is there any difference from regular images?</li><li>Add presenter notes to one or more slides.</li><li>Try to add animations between slides. Is it possible?</li></ul> Feel free to share results with us on Twitter – <a href="https://twitter.com/appsilon" target="_blank" rel="noopener noreferrer">@appsilon</a>. We’d love to see what you come up with. <blockquote><strong>R isn’t limited to Markdown only. <a href="https://appsilon.com/best-r-shiny-books-and-courses/" target="_blank" rel="noopener noreferrer">Here are the top free resources if you want to learn R Shiny</a>.</strong></blockquote>

Contact us!

Damian's Avatar

Read about simillar topics

gganimate

Race Charts in R: How to Visualize and Compare Change Over Time with gganimate

powerpoint presentations with r markdown

R gganimate: How to Make Stunning Chart Animations with ggplot2

5 Ways R Programming and R Shiny Can Improve Your Business Workflows

5 Ways R Programming and R Shiny Can Improve Your Business Workflows

Take your business further with custom data solutions.

Unlock the full potential of your enterprise with our data services, tailored to the unique needs of Fortune 500 companies. Elevate your strategy—connect with us today!

logo

Matt Herman

Recently at work , I’ve been building R Markdown documents to generate PowerPoint slides. In general, this is a pretty straightforward process and is described in R Markdown: The Definitive Guide . One limitation they note is:

Images and tables will always be placed on new slides. The only elements that can coexist with an image or table on a slide are the slide header and image/table caption. When you have a text paragraph and an image on the same slide, the image will be moved to a new slide automatically.

That is a bummer for me because the original PowerPoint slides I am trying to replicate using R Markdown have multiple images and tables on them. An alternative to using PowerPoint would be xaringan and doing some fancy layout using CSS, but I’m not very good at CSS and we need the slides in PowerPoint format because other folks at the office add additional slides to the presentations I generate.

Around this time, I was reading tweets about new development on the patchwork package for arranging ggplot objects, and thought that instead of including multiple images on one slide, I could just create a multi-image layout in R and then render that layout to the PowerPoint slide.

In this post, I show how to combine plots and tables using patchwork to create multi-image PowerPoint slides using R Markdown.

I’m going to use data from the gapminder package , so if you don’t have it installed:

On my slide, I want to include 2 plots and 1 table related to life expectancy of certain counties in East Africa. I’m going to start by making the plots and then I’ll combine them in a single layout, and finally render the image to PowerPoint.

First, I load the needed packages and filter the gapminder data to the five countries in East Africa I’m going to be examining.

If you haven’t worked with the gapminder data before, take a peak. There is one row per country per year, with life expectancy, population, and GDP for each observation.

The first plot I’m going to make is a bar chart of life expectancy by country for the most recent year of data, 2007.

powerpoint presentations with r markdown

Next, a line chart to look at the trend in life expectancy by country over time.

powerpoint presentations with r markdown

Lastly, a table with life expectancy, population, and GDP for each country for the most recent year of data. To make a table that I can combine with the above ggplots, I’ll use gridExtra::tableGrob() , which renders tables as grobs ( grid graphical objects ).

powerpoint presentations with r markdown

Alright, I’ve got the three graphical elements I want to combine into one layout on a single slide. Now comes the magical patchwork package to assemble these elements into one graphic.

I’m thinking this will look best with the bar chart and table side-by-side on the top half of the slide and the line chart below them. To do this, I take the elements created above and describe their arrangement using the fun patchwork syntax . Then, I’ll add a title and caption to finish off the layout.

powerpoint presentations with r markdown

All that’s left to do is to get this onto a PowerPoint slide!

First, create a new R Markdown document and specify powerpoint_presentation as the output format in the YAML header:

If you want to use a PowerPoint template, you can specify a reference document in the header. This can be useful if you need to match a corporate brand or theme.

Then, in the body of the R Markdown file, create a code chunk with all the above code to create the plots and layouts. Finally, click the Knit button from RStudio or run rmarkdown::render() to generate the PowerPoint presentation. And here is a screenshot of resulting presentation:

powerpoint presentations with r markdown

One thing that took a little trial and error was setting the fig.width and fig.height options of the knitr chunk as well as the dimensions of the content area in the PowerPoint template so that the patchwork layout fills the slides appropriately.

This example demonstrated how to make a singe PowerPoint slide with multiple images using patchwork. But of course, one of the super powers of programmatically creating slides is that you can very easily create a second or third or fourth slide with other countries specified. One nice way to implement this would be to use a parameterized child document and iterate through different sets of countries. (Next blog post, perhaps?)

You can find the complete R Markdown file , the PowerPoint template I used , and the rendered PowerPoint on GitHub.

  • United States
  • United Kingdom

How to create PowerPoint slides from R

Learn how to generate powerpoint slides straight from an r markdown document. plus, create interactive html slides in r with the xaringan package..

Executive Editor, Data & Analytics, InfoWorld |

How to create PowerPoint slides from R

There are lots of ways to share results of your R analysis: Word documents , interactive apps , even in the body of an email .

But sometimes, you want a slide presentation. It’s easy to generate a PowerPoint file from your R code – complete with charts and graphs – directly from an R Markdown document.

Create a PowerPoint from R Markdown

To create a PowerPoint from R, you need three things on your system:

  • PowerPoint or OpenOffice,
  • The rmarkdown package, version 1.9 or later, and
  • Pandoc version 2.0.5 or newer.

Pandoc isn’t an R package. It’s not R at all; it’s a separate piece of open source software designed for file format conversions.

RStudio ships with Pandoc, so you probably have a version of it installed if you use RStudio. You can run the rmarkdown package’s pandoc_version() function to see if you’ve got it installed and, if so, what version. If your pandoc is too old, try updating RStudio (or install pandoc directly from pandoc.org ).

There is an option to create a PowerPoint file from R Markdown when you create a new markdown file in RStudio.

Next, create an R Markdown document. If you do that from RStudio’s menu with File > New File > R Markdown, you’ll have a few choices . If you click on the second choice, Presentation, you should see an option for PowerPoint under Default Output Format.

The resulting R Markdown file created by RStudio includes examples for mixing text and R code results. If you save that file and then “knit” it by clicking the knit button in RStudio, you'll get a PowerPoint presentation with the same information.

How did R know where to break the content into new slides? The default is “the highest level of headline that’s not followed immediately by another headline.” In this case that’s headline level two, or all titles starting with ## .

You don’t need to use that default rule, though. You can specify another headline level to auto-divide your document into new slides. That’s done in the doc’s YAML header  with the slide_level option, such as

But if you don’t want to fiddle with all that, you can divide content into new slides manually with three dashes. Make sure the three dashes are on a completely new line.

Presenting the weather

Here is an R Markdown file that’s a bit more interesting than the default doc, at least for me: One with weather data.

Notice the R chunk options I’ve set.  echo = FALSE  means my R code won’t show up in my slides. warning and message set to FALSE makes sure any warnings or messages from my code don’t appear in the slides either. I’ve also set a default figure width and cache = TRUE  . (I don’t usually cache results for a file I want to update regularly, but I did so to save time on the accompanying video.)

Get National Weather Service forecast data via R

My R Markdown setup code chunk also sources a separate file on GitHub that includes two functions for fetching weather data. Here is that code, if of interest:

The first function pulls a forecast data frame from the National Weather Service API using the city name and the city’s forecast URL as function arguments. 

You need to know the API’s forecast URL for a location in order to get its forecast data. If you don’t know that URL, you can get it from another National Weather Service API using the format 

The initial API result from the httr GET request is a list. The function adds code that returns only the portion of the list with the data I want, formatted as a data frame.

The second function takes that forecast data frame and generates a ggplot line graph for high and low temperatures.

Change the PowerPoint default font

If you want a different default font or font size for your R-generated slides, you can set those with a reference PowerPoint document and add info about that document in the R Markdown YAML header. I did that for these slides, as you can see in this portion of the YAML document header:

My reference file, CorporateStyle.pptx ,  is a regular PowerPoint file and not a PowerPoint template. To turn it into a reference file, I went into the file’s Master Slide view and set some styles. You can edit any PowerPoint file’s Master Slide view in the PowerPoint menu with View > Slide Master.

Whenever I want an updated version of that forecast PowerPoint, I just need to re-knit the document. I could even set this up to run automatically using Windows scheduler or launchd on a Mac.

Create HTML slides from R

There might be many times when you specifically need or want a PowerPoint file. One thing PowerPoint slides lack, though, is interactivity. For example, you can’t roll over a graph and see underlying data.

You could if these were HTML slides, though.

There are a few ways to generate HTML slides from R. One of the most popular is with the xaringan R package . xaringan is built on top of the remark.js JavaScript library. There is a bit of a learning curve to do more than the basics, but the look and feel are extremely customizable.

xaringan would need its own series to cover all you can do with it. But even basics can work for a lot of use cases. Below is an example of an R Markdown document with just a bit of customization.

Three dashes create a new slide. That first slide after the title slide won’t display; it’s setting defaults for the other slides. layout: true means “this is a slide setting up layout defaults.” class: center centers everything – header text, graphics – unless I specifically code it otherwise. 

The xaringan::moonreader output option regenerates the slides each time you save the file so you don’t need to click the knit button. 

The body of the file includes a graphing function I wrote using one of my favorite dataviz packages, echarts4r , to visualize my weather data. You can hover over lines on the graphs in these slides to see underlying data, as well as click legend items to turn lines off and on.

An HTML slide presentation lets you interact with visualizations, such as hovering over a graph to see underlying data.

There is a ton more you can do with xaringan, from adding your own CSS file to creating your own theme to animating slides. Here are some resources to learn more:

  • xaringan slide presentation about xaringan by creator Yihui Xie
  • Incremental slides with xaringan by creator Yihui Xie
  • xaringan presentations from R Markdown: the Definitive Guide by Yihui Xie, J. J. Allaire, and Garrett Grolemund
  • xaringan gallery of examples and themes by Emil Hvitfeldt
  • Meet xaringan: Making slides in R Markdown by Alison Hill (RStudio Conference 2019 workshop slides)
  • xaringanExtra package (enhancements and extensions to the xaringan package) by Garrick Aden-Buie
  • xaringanthemer package (lots of xaringan styling options)  by Garrick Aden-Buie

And for more R tips, head to the Do More With R page .

Next read this:

  • Why companies are leaving the cloud
  • 5 easy ways to run an LLM locally
  • Coding with AI: Tips and best practices from developers
  • Meet Zig: The modern alternative to C
  • What is generative AI? Artificial intelligence that creates
  • The best open source software of 2023
  • Business Intelligence
  • Data Visualization

Sharon Machlis is Director of Editorial Data & Analytics at Foundry, where she works on data analysis and in-house editor tools in addition to writing. Her book Practical R for Mass Communication and Journalism was published by CRC Press. She was named Digital Analytics Association's 2021 Top (Data) Practitioner, winner of the 2023 Jesse H. Neal journalism award for best instructional content, 2014 Azbee national gold award for investigative reporting, and 2017 Azbee gold for how-to article, among other awards. You can find her on Mastodon at masto.machlis.com/@smach .

Copyright © 2022 IDG Communications, Inc.

powerpoint presentations with r markdown

nandeshwar.info

  • Data Science >>
  • Create PowerPoint Presentations with R and RMarkdown

powerpoint presentations with r markdown

In this post, you will learn how to create PowerPoint presentations using R and RMarkdown. There are other presentation options in RMarkdown and RStudio such as ioslides, slidy, and beamer , but for this post, we will focus on PowerPoint presentations. 

We will see three ways of creating PowerPoint presentations:

  • Using the default RMarkdown option
  • Using a custom PowerPoint template
  • Using officedown/officer R libraries for further customization

Before we jump into creating these presentations, I would like to share a quick overview of PowerPoint and presentation design best practices from two books: Presentation Zen and Strategic Storytelling.

Presentation Zen

Garr Reynolds, the author of Presentation Zen , recommends the use of full-bleed background images with one sentence, a word, or statistic. He also recommends using the rule of thirds to place the point of focus in the intersection of lines dividing the slide into three equal sections horizontally and vertically. We will see whether we can make that happen. He also suggests using simple charts to make your point. Although these types of presentations are better for keynotes, we will try to apply some of these principles.

Strategic Storytelling

Dave McKinsey, the author of Strategic Storytelling , provides examples from top management consulting companies such as McKinsey and Accenture. He explains why these business presentations work. Some of the main points from this book are:

  • Use of the Minto principle
  • Use the slide title to make your point or ask a question
  • Use of body content to support your point mentioned in the title

Let’s talk about the Minto principle also called the Minto Pyramid.

Barbara Minto  was McKinsey consulting’s first female MBA professional. She invented the Minto pyramid to help consultants make effective business presentations. It provides a good structure for organizing your presentation content. You start with your main idea or recommendation. Then provide the supporting arguments with data and facts. Each supporting argument is further supported by more arguments and data. If you notice any of the consulting company’s presentations, you will see they have many charts, call-outs, and notes with references. 

With these presentation design best practices, let’s dive into creating PowerPoint presentations with R and RMarkdown.

For this post, let’s say that we are studying the streaming services market. Our client is a company trying to enter in this market.

Here’s how we will structure the presentation :

  • Slide 2: Our main recommendation.
  • Slide 3: Survey of the market: share prices
  • Slide 4: Survey of the market: market share
  • Slide 5: Opportunities
  • Slide 6: Side by side comparison of Netflix and Disney+
  • Slide 7: Conclusion

PowerPoint presentation created in R example

Let’s get started.

First, let’s make sure you can build the example PowerPoint presentation in RStudio.

To start a new markdown document, click on File, New File, R Markdown, then Presentation, and finally PowerPoint. 

The title is of my presentation is “Streaming Services Market Study” and the author is “Best Brians Consulting” (It is Brians and not brains after the movie Life of Brian)

Make sure that this document compiles and gives you a nice PowerPoint presentation. 

Click on the “knit” button. Save your file. If everything works out, you should have a new PowerPoint presentation. 

If everything worked out, edit the RMarkdown document with the new content for this streaming services presentation.

First, let’s change the knitr options to cache the data and suppress warnings and messages.

The first slide has recommendations. 

Our next slide has data with the share prices of the companies in this space.

Following the “Strategic Storytelling” book example, the title of our slide is: Companies such as Netflix have cemented their roles as streaming entertainment providers

This R code pulls the historical share prices of Netflix, Disney, and Comcast, ATT, and shows a ggplot multiple line plot . It could be made prettier and more valuable with annotations, but for this exercise, it is good enough.

A multiple line plot with share prices for a PowerPoint presentation created using R and RMarkdown

Our next slide is the market share data.

This R code creates a treemap of market share data using ggplot and treemapify. This chart could also be made better, but this will do for now.

A tree map created using R and Rmarkdown for PowerPoint

The next slide is a chart from a website showing opportunities. I have used include_graphics from knitr to add the image. I have also added a caption by using fig.cap option.

Next up is a case study of Disney+ vs. Netflix. I am using a two-column layout using a special Pandoc syntax. Within each column, I have a column header and a bulleted list. I also added the source in the first column.

Lastly, we have the conclusion slide with one sentence. 

After hitting knit, you will see that the PowerPoint presentation has the line plot and the treemap we generated using ggplot.

It also has an external image from a URL.

It created the two-column layout as well.

But you notice some other problems too.

  • Page numbers are missing.
  • The aspect ratio is not 16 by 9.
  • The slide titles are aligned in the center and the long title doesn’t fit neatly.
  • Both the charts are taking the same smallish space.
  • The conclusion slide looks bland.

We can resolve some of these issues by providing our custom PowerPoint template. 

  • Create a new PowerPoint presentation. 
  • Then edit the layouts. 
  • Go to View and click on Slide Master.

Here you will see all the default layout options.

RMarkdown and Pandoc  currently support only these four layouts:

  • title and content
  • section header, and
  • two-column layout

That means we can customize only these four layouts. 

  • Edit the master slide first.
  • Click on the “click to edit” text box.
  • Change the font type to your liking. I selected “Lato” for the title.
  • Next, I am selected Corbel for the body or content area.
  • Add custom text boxes in the footer for date and page numbers.
  • Insert the date and slide number from the Insert menu.
  • Change the font type and size.
  • Then delete all the existing boxes for footers.
  • I added a logo in the center of the slide. I created this simple logo using Logomakr.com

Let’s also change the background color of the slides to something light. I chose #edf6f9 as the background color.

  • Go to Background Styles. 
  • Format Background. 
  • Click on Color and then more colors.

Let’s also change the color of the slide title. I chose #006d77.

Save the PowerPoint template. Add a reference in the YAML in your RMarkdown to this PowerPoint template like this:

Hit the “knit” button to see the results.

You can change the font type of the plots to match your presentation font type by using the “showtext” library. But I leave that for you.

If you have a simple presentation, this can work very well. You pull all your data in one place, create your charts, and add recommendations. You can edit the PowerPoint later, of course, but for repeatability , we want to keep as many things in RMarkdown as possible.

One disadvantage of this approach using Pandoc is that we are limited to only four layouts. If you wanted to add one title and one subtitle to your layout, it won’t work. Another disadvantage is an image or a table can’t exist with other content. If you add content to a slide that already has a chart or an image, it will get pushed to a new slide.

You can get around this problem using patchwork or similar libraries to place side-by-side graphs, tables, and text. But that may not give you the best resolution. We also can’t add random texts or call-outs.

There’s an option to add background images in HTML presentations, but it doesn’t work for PowerPoint.

Let’s explore the office and officedown libraries for further customization. You can use the officedown in YAML as officedown::rpptx_document and provide a template, but I don’t know the exact advantages of doing so.

Instead, we will create an R file and build the PowerPoint presentation one slide at a time.

Let’s load the officer and magrittr libraries.

Next, we will load our template file using the read_pptx function in a variable called my_ppt.

With the layout_summary function, we can check all the layouts available to us.

Add a new layout to your PowerPoint template with one text box and increase the font size to 80. Rename this layout to ‘one big number’.

Save the template and read the file again.

Now when you run layout_summary you will see that this new layout is available to us.

The layout_properties function lets us see the available content areas we can change.

This is an important function. Notice the `ph type` argument value. We need to use the value of `ph type` to set the content.

It will be easier with an example.

Let’s create our first slide with the presentation title slide.

To add a slide we use add_slide function. To this function, we specify the layout and the theme to use.

To add content we use the ph_with function. The value argument of this function specifies the content.

And now the important part: where do we want the content to go? To find the location, we use ph_location_type function and pass the type we saw in ph type.

For the opening, title slide the box is called ctrTitle.

Let’s add our title.

Also, add the author to ph type of subtitle.

Let’s save this new presentation using the print command.

Open the PowerPoint and check whether you can see the title and subtitle.

Let’s add the second slide with recommendations. But check the available shape types using the layout_properties function for the Title and Content layout. You will that we have a title and body types available.

Let’s add ‘recommendations’ as the title and pass the bullet points for this slide as a vector to the body location.

Save the document again and see what it looks like.

Next, add a slide with the share prices chart, but we need to create this chart first. This code will save the chart in a ggplot object called share_prices_plot.

We will again use title and body locations to add this plot and the title. The only difference is that we can provide a resolution of the chart.

Next, let’s add the tree map with the market share

With the default RMarkdown/Pandoc option, we can place an image and text side-by-side, but let’s try that with the officer package and the ‘Picture with Caption’ layout.

We can see we have body, title, and pic locations available for us with the ‘Picture with Caption’ layout.

Let’s add the year-over-year market share comparison chart from the wrap in the pic location and some text in the body location.

Let’s add and save the file again.

I don’t like the location of the source text. I want to move it close to the footer.

To do so, I need to first create a style or properties I want to apply to this text.

We will use the fp_text function to make the text color light gray and set the font size to 8.

We will name this variable source_box_style. 

To add a text box at any location, we need to provide the text box location using the left, top, and other coordinates to the ph_location function. 

And to get the text box to show up on the slide, we need to use the fpar function, which creates a paragraph object for PowerPoint. In fpar, we will wrap our source text and provide the style property we created earlier with the ftext function. 

Here are the steps again to create a text box:

  • Define style or properties
  • Decide and provide the coordinates to ph_location function
  • Format the given text using the style and ftext function, and
  • finally wrap the ftext call in fpar function to create a paragraph object

You can find the location coordinates by creating a box in PowerPoint and adjusting it. To make it easier, I saved the location object in a variable called source_box_location. 

Save the PowerPoint presentation again. 

Using this same principle, let’s create a callout box and add it to the share prices slide. I created callout_box_style and callout_box_location.

To select the slide with share prices, we need to use “on_slide” function and provide the slide number. 

Make this change and then save the presentation again.

Of course, it would be easier to draw the text box later in the PowerPoint, but this gives an additional tool to place text boxes with dynamic content at our chosen locations. 

For the final addition, I would like to add a background image that bleeds into the slide and add some text on it. We will use the one big number layout we created earlier. 

Let’s check the layout properties. We see the property name as “one big number.”

I downloaded a photo from unsplash. I named it tv-3.jpg, whose path I am storing in bg_image_path variable. 

Next, let’s add a slide using the add_slide function and “one big number” as the layout. 

Then we will use the ph_with function to place the external image and 13.38 as the width and height. We will use the ph_location_fullsize function to return the proper dimensions from the slide layout. 

Lastly, we will use another ph_with function to add the text of “31% drop” at the text placeholder location. 

These steps should give you a good-looking PowerPoint presentation using RMarkdown . Here’s the summary of our process:

  • We created a PowerPoint presentation using the default knitr options in RMarkdown. It worked well but didn’t offer customization. 
  • Therefore, we created a PowerPoint template to make the presentation look better, and it did!
  • But for more control, we looked at the officer R package and created our layouts, and placed objects where we wanted them.

I hope this helps you when you are trying to create PowerPoint presentations using R and RMarkdown. Let me know what you think by leaving a comment. 

Related Posts

Machine Learning vs. Deep Learning – What is the Difference?

Survey of Predictive Analytics in Fundraising

How to Automate Statistical Analysis using RMarkdown

All Data Has A Story. Here’s How to Tell it

How to Use OpenAI’s GPT-2 to Create an AI Writer

About the Author

A co-author of Data Science for Fundraising, an award winning keynote speaker, Ashutosh R. Nandeshwar is one of the few analytics professionals in the higher education industry who has developed analytical solutions for all stages of the student life cycle (from recruitment to giving). He enjoys speaking about the power of data, as well as ranting about data professionals who chase after “interesting” things. He earned his PhD/MS from West Virginia University and his BEng from Nagpur University, all in industrial engineering. Currently, he is leading the data science, reporting, and prospect development efforts at the University of Southern California.

R-bloggers

R news and tutorials contributed by hundreds of R bloggers

Mastering r presentations.

Posted on September 23, 2019 by R on Coding Club UC3M in R bloggers | 0 Comments

[social4i size="small" align="align-left"] --> [This article was first published on R on Coding Club UC3M , 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.

by Paula LC

Do you want to know how to make elegant and simple reproducible presentations? In this talk, we are going to explain how to do presentations in different output formats using one of the easiest and most exhaustive statistical software, R. Now, it is possible create Beamer, PowerPoint, or HTML presentations, including R code, \(\LaTeX\) equations, graphics, or interactive content.

After the tutorial, you will be able to create R presentations on your own with R Markdown in RStudio. But don’t worry if you don’t know a lot of R Markdown, because it’s really simple to use it with RStudio and you will discover the keys to master the language.

We have several options to create amazing technical presentations in pdf format with tools like PowerPoint or \(\LaTeX\) . But the truth is that when we want to generate a full and complete document with graphs, code, and text, then we invest more time in the appearance than in the content itself, or learning how to add content easily. So here I want to show you a good alternative using R. The best feature R has is the flexibility and simplicity of the code to reproduce amazing presentations with little work. To achieve it, R uses Markdown. But, what is exactly Markdown?

What is Markdown?

Markdown is a simple language to write web-based content easy both for writing and reading. The key is that it can be converted to many output formats with a simplified syntax.

Basics of Markdown

Here you have a summary guide of the main style syntax.

Code and syntax highlighting

Blockquotes, tex formula.

Besides these basics, you can to add tables, rulers, links to videos, HTML code, etc. To know more visit the creator’s web site: https://daringfireball.net/projects/markdown/ or this cheatsheet https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet .

R has a specific file format for this type of documents .Rmd . R Markdown has an online book really useful and detailed here https://bookdown.org/yihui/rmarkdown/ . This tool let you build different type of documents like the next ones:

  • Documents : HTML, \(\LaTeX\) /PDF, Microsoft Word, Tufte-style handouts
  • Interactive documents : HTML Widgets, Shiny
  • Dashboards : Gauges, values boxes, HTML Widgets, Shiny, Storyboard
  • Books : HTML, PDF, EPUB
  • JSS templates, R Journal, Skeleton, CV
  • Package Vignettes
  • Presentations : Beamer, Slidy, ioslides, reveal.js, xaringan

In the next link, you will find some examples of each one https://rmarkdown.rstudio.com/gallery.HTML . And in this cheatsheet, a good summary of R Markdown is presented https://rmarkdown.rstudio.com/lesson-15.HTML .

How to start

The first step is to get R and RStudio, and install the package rmarkdown with the code

In the last versions you can directly create presentations going to File -> New File -> R Presentation . Then, a .RPres document is going to be created. This is the simplest, really simplest, way to start but my advice is to go quickly to the next step if you want more flexibility in the slides and final appearance.

So going to File -> New File -> R Markdown and selecting the option Presentation , you are going to have different options to create your slides. Selecting any of them, a file like this is automatically generated:

powerpoint presentations with r markdown

Depending on the final style of the output there are different output options. In the next points, we are going to explain in detail the main features of all them.

  • ioslides : the option output: ioslides_presentation
  • slidy : the option output: slidy_presentation
  • beamer : the option output: beamer_presentation

The R Markdown file

The header is the R Markdown document part where you can set the title, the author, the date, and the output as the image shows:

But at the same time, other options can be determined as follows:

Once the header is completed, you can add any kind of content that you can practically imagine: R code, equations, charts, images, videos etc. In the next points we are going to see how to add each type of content.

In addition to plain text, headers and other Markdown elements, you have the option of inserting R code which will be executed every time you run the file. These parts of the document are called R chunks . To insert an R Chunk you can use RStudio toolbar Insert button or the keyboard shortcut Ctrl + Alt + I on Windows and Cmd + Option + I on macOS.

There are a lot of options referring to how to include tables, text output, figures, etc. For example, to add the option to show in the output the R code before the results you have to add between the brackets {r } the option echo as follows {r echo=TRUE} . By default, the code is not shown.

More options:

  • cache : cache results for future knits (default = FALSE)
  • cache.path : directory to save cached results in (default = “cache/”)
  • child : file(s) to knit and then include (default = NULL)
  • collapse : collapse all output into single block (default = FALSE)
  • comment : prefix for each line of results (default = ‘##’)
  • dependson : chunk dependencies for caching (default = NULL)
  • echo : Display code in output document (default = TRUE)
  • engine : code language used in chunk (default = ‘R’)
  • error : Display error messages in doc (TRUE) or stop render when errors occur (FALSE) (default = FALSE)
  • eval : Run code in chunk (default = TRUE)
  • message : display code messages in document (default = TRUE)
  • results=asis : passthrough results
  • results=hide : do not display results
  • results=hold : put all results below all code
  • tidy : tidy code for display (default = FALSE)
  • warning : display code warnings in document (default = TRUE)
  • fig.align : ‘lef’, ‘right’, or ‘center’ (default = ‘default’)
  • fig.cap : figure caption as character string (default = NULL)
  • fig.height, fig.width : Dimensions of plots in inches
  • highlight : highlight source code (default = TRUE)
  • include : Include chunk in doc after running (default = TRUE)

In the next link you can find more details about R chunks: https://bookdown.org/yihui/rmarkdown/r-code.HTML

There is the chance to add equations to your presentations with MathJax scripts. These are included in HTML documents for rendering \(\LaTeX\) and MathML equations. To control how MathJax is included you have the next options:

  • default to use an HTTPS URL from a CDN host (currently provided by RStudio)
  • local : to use a local version of MathJax (which is copied into the output directory). Note that when using “local” you also need to set the self_contained option to false.
  • URL indicating the location to load MathJax
  • null to exclude MathJax entirely.

For example, to use a local copy of MathJax:

To use a self-hosted copy of MathJax:

You have four options to add tables. First one, directly from R Markdown

or the next ones, from R code with the libraries knitr , xtable , or stargazer .

Interactive graphs

In R there are a lot of packages to create interactive graphs. Highcharter is one of them, as well as the well-known HTMLwidgets . Here we have an example of a highcharter graph.

Presentation formats

We just explored the different contents and parts of our R Markdown document. Let’s see what type of output format we can obtain.

Ioslides is a nice R presentation format characterized by the simplicity of the result. There are some features specific from ioslides, such as the display mode

  • f : enable fullscreen mode
  • w : toggle widescreen mode
  • o : enable overview mode
  • h : enable code highlight mode
  • p : show presenter notes

or the incremental bullets:

Moreover, you can change the presentation size, the text size, or even the transition speed in the header of the document. Specifically, for the transition speed you can set the number of seconds for each slide or use the standard options: default , slower , faster .

For another hand, there is a quick way to add a background image without editing the CSS file,

But if you want to add specific style changes to your presentation, I recommend you to edit the CSS file and add it to the header of the RMarkdown document:

One of the disadvantages of ioslides is that customization is limited compared with other output formats. At the end of this tutorial we explain how to modify by your own a CSS file.

Slidy has more flexibility than ioslides as to appearance and style. Now we are going to see some of the main special features that slidy has.

There is the chance to change the display mode with the next shortcuts;

  • c : Show table of contents
  • c : Toggles the display of the footer
  • a : Toggles display of current vs all slides (useful for printing handouts)
  • s : Make fonts smaller
  • b : Make fonts larger

And we can adjust the font directly in the header of the document without editing the CSS file:

You will find other interesting features of slidy such as the countdown timer in the footer or the customized footer text that can be easily added with the options duration and footer .

Slidy themes

In slidy, there are different Boostrap themes to use drawn from the Bootswatch theme library. The themes are default , cerulean , journal , flatly , darkly , readable , spacelab , united , cosmo , lumen , paper , sandstone , simplex , and yeti . To add your own style with a CSS file, pass null in the theme parameter.

Moreover, the syntax highlighting style can be specified with the option highlight . Supported styles are default , tango , pygments , kate , monochrome , espresso , zenburn , haddock , and textmate . And you have the option of preventing syntax highlighting passing null to the parameter.

Beamer is a \(\LaTeX\) class to produce presentations and slides. It is so common in academia and so useful to add mathematical formulas and expressions. You can create your own Beamer presentations from R without a deep knowledge of \(\LaTeX\) (only Markdown).

So the first step is to install tex. Tex is a typesetting for complex mathematical formulae used in \(\LaTeX\) . To install it, download tone of the next programs, depending on your OS system: - MikTeX on Windows - MacTeX 2013+ on OS X - TeX Live 2013+ on Linux

Beamer themes are the same that you can find in \(\LaTeX\) . In the next link https://hartwork.org/beamer-theme-matrix/ you have the list of the different available header options related to the appearance and style:

There are other interesting options to create presentations in R such as reveal.js and xaringan. Reveal is very well-known because of the flexibility in the themes and transitions by default, the vertical slides or the possibility to include a web site inside a slide. In this part, we are going to explain how to generate a revealjs file and the main features of this awesome library.

First of all, it is required to install revealjs package

Then, you can directly change in the R Markdown document header the output argument to revealjs_presentation or go to menu File -> New File -> R Markdown -> From template and select reveal.js presentation.

powerpoint presentations with r markdown

There are some amazing keyboard shortcuts:

- f for fullscreen - o or ESC for overview mode - alt or ( ctrl in Linux) and click an element, to zoom this element - s for speaker view (so pretty!) - B or . to pause the presentation

And there is a lot of variety about appearance and styles. If you want to change how the presentation looks like, you can choose any of the next theme options: default , simple , sky , beige , serif , solarized , blood , moon , night , black , league , and white . And for the syntax highlighting style: default , tango , pygments , kate , monochrome , espresso , zenburn , and haddock . Pass null to prevent syntax highlighting. The way to specify it is the same than the previous presentation types.

In revealjs you can center the text of the slides changing the center option to true, which by default is false, as well as the possibility of modifying the transitions and backgrounds, i.e. how the slide is going to move to the next one. Available transitions and background_transitions are default , fade , slide , convex , concave , zoom or none . Any of these global options can be overriden specifying the data-transition attribute in the header of the slide:

Moreover, Revealjs lets add different backgrounds like color, image, video, and iframe:

Finally, you can specify the level of heading will be used with the slide_level option. For example, if the slide_level is 2, the level-1 headers will be built horizontally and level-2 headers, vertically.

Other interesting features are the great look on touch devices, the fragmented slides, easy to export to pdf, keyboard bindings, or the parallax scrolling background.

References https://CRAN.R-project.org/package=revealjs .

Ninja presentation

The last type of presentations that we are going to see is the xaringan library. It is an R Markdown extension based on the JavaScript library remark.js ( https://remarkjs.com ). This package was originally designed for “ninja”, so it is recommended to people that have a well-known of CSS. For another hand, if you need slides to be self-contained, then xaringan it is not a good option because needs a webserver to run. Another bad news is that xaringan doesn’t work well with HTML widgets.

To install the library type

or install it directly from GitHub to ensure that you are downloading the last version

Once you get installed, go to the menu File -> New File -> R Markdown -> From template and click on ninja presentation.

powerpoint presentations with r markdown

Note: If you understand chinese you can select the last option ;).

The header is going to look like this

A lit bit more complicated than others and as you will see, there are some funny arguments that make this library really different.

  • css : to add your own CSS file,
  • self_contained : to produce a self-contained HTML file
  • seal : to generate a title slide automatically using the YAML metadata of the R Markdown document (if FALSE, you should write the title slide by yourself)
  • yolo : to insert the Mustache Karl (TM) randomly in the slides. Using TRUE, a number between 0-1 to insert the Mustache Karl in a percentage of the slides, or even a list(times = n, img = path)
  • chakra : path to the remark.js library (can be either local or remote).
  • nature : (Nature transformation) A list of configurations to be passed to remark.create(), e.g. list(ratio = ‘16:9’, navigation = list(click = TRUE)); see https://github.com/gnab/remark/wiki/Configuration

Besides the options provided by remark.js, there are others such interesting like autoplay the slides or the countdown timer. Slides can be automatically played setting the autoplay option under nature (in milliseconds). For example, to display slides every 30 seconds and see the countdown timer:

It is possible to highlight code lines turning the option highlightLines to true or to extend the markdown syntax defining custom macros with the beforeInit option under the option nature.

Adding your CSS file

Some of the previous presentation formats give us the chance to add a customized CSS file. To know how to change a specific element you can inspect it with any web browser and focus exactly on what you want to modify by yourself. An example of a basic modification in a CSS file is the next one. Here we are selecting the background color of the body, the color of the headers and the full text for the reveal presentation, and the size of the h1 header:

Then you have to save the CSS file in the same path that your R presentation document.

How to export the presentation

With all the HTML output it is possible to export the presentation to pdf with any web browser using the menu Print to PDF from Google Chrome, for example. But there is another alternative like publishing the presentation online in RPubs or GitHub. You must be registered in any of the two platforms to be able to add your work. For RPubs, you have to invoke the More -> Publish to RPubs command from the presentation toolbar, and in GitHub, you have to create a new repository with the HTML document and all the style files associated, and enable to GitHub pages to this repository. Here you have the steps to do it: https://pages.github.com/ .

Basic example

Finally, let’s show you a simple reveal.js example to get you started.

After knitting this, here is the result:

Conclusions

RStudio is an awesome framework that provides you the chance to create nice presentations with a simple syntax, adding interactive content, and with a professional and modern style. Moreover, your presentation will be reproducible if you want to make any change, as well as you can save your templates to use them in the future. In my opinion, it is a really good alternative to other traditional software to create presentations and so easy to work with it. I hope it is so useful for you too 🙂

To leave a comment for the author, please follow the link and comment on their blog: R on Coding Club UC3M . 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.

Copyright © 2022 | MH Corporate basic by MH Themes

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

R Markdown: The Definitive Guide

Chapter 4 presentations.

For documents, the basic units are often sections. For presentations, the basic units are slides. A section in the Markdown source document often indicates a new slide in the presentation formats. In this chapter, we introduce the built-in presentation formats in the rmarkdown package.

8   Slideshow Presentations

You are reading the free online version of this book. if you’d like to purchase a physical or electronic copy, you can buy it from no starch press , powell’s , barnes and noble or amazon ..

If you need to create a slideshow presentation, like one you might create in PowerPoint, R has you covered. In this chapter, you’ll learn how to produce presentations using xaringan . This package, which uses R Markdown, is the most widely used tool for creating slideshows in R.

You’ll use xaringan to turn the penguin report from Chapter 6 into a slideshow. You’ll learn how to create new slides, selectively reveal content, adjust text and image alignment, and style your presentation with CSS.

Why Use xaringan?

You might have noticed the Presentation option while creating a new R Markdown document in RStudio. This option offers several ways to make slides, such as knitting an R Markdown document to PowerPoint. However, using the xaringan package provides advantages over these options.

For example, because xaringan creates slides as HTML documents, you can post them online versus having to email them or print them out for viewers. You can send someone the presentation simply by sharing a link. Chapter 9 will discuss ways to publish your presentations online.

A second benefit of using xaringan is accessibility. HTML documents are easy to manipulate, giving viewers control over their appearance. For example, people with limited vision can access HTML documents in ways that allow them to view the content, such as by increasing the text size or using screen readers. Making presentations with xaringan lets more people engage with your slides.

How xaringan Works

To get started with xaringan , run install.packages("xaringan") in RStudio to install the package. Next, navigate to File > New File > R Markdown to create a new project. Choose the From Template tab and select the template called Ninja Presentation , then click OK .

You should get an R Markdown document containing some default content. Delete this and add the penguin R report you created in Chapter 6 . Then, change the output format in the YAML to xaringan::moon_reader like so:

The moon_reader output format takes R Markdown documents and knits them as slides. Try clicking Knit to see what this looks like. You should get an HTML file with the same name as the R Markdown document (such as xaringan-example.html ), as shown in Figure  8.1 .

powerpoint presentations with r markdown

If you scroll to the next slide with the right arrow key, you should see familiar content. Figure  8.2 shows the second slide, which has the same text as the report from Chapter 6 and a cut-off version of its histogram.

powerpoint presentations with r markdown

Although the syntax for making slides with xaringan is nearly identical to that used to make reports with R Markdown, you need to make a few tweaks so that the content can fit on the slides. When you’re working in a document that will be knitted to Word, its length doesn’t matter, because reports can have 1 page or 100 pages. Working with xaringan , however, requires you to consider how much content can fit on a single slide. The cut-off histogram demonstrates what happens if you don’t. You’ll fix it next.

Creating a New Slide

You’ll make this histogram fully visible by putting it in its own slide. To make a new slide, add three dashes ( --- ) where you’d like it to begin. I’ve added them before the histogram code:

When you knit the document again, what was one slide should now be broken into two: an Introduction slide and a Bill Length slide. However, if you look closely, you’ll notice that the bottom of the histogram is still slightly cut off. To correct this, you’ll change its size.

Adjusting the Size of Figures

Adjust the size of the histogram using the code chunk option fig.height :

Doing this fits the histogram fully on the slide and also reveals the text that was hidden below it. Keep in mind that fig.height adjusts only the figure’s output height; sometimes you may need to adjust the output width using fig.width in addition or instead.

Revealing Content Incrementally

When presenting a slideshow, you might want to show only a portion of the content on each slide at a time. Say, for example, that when you’re presenting the first slide, you want to talk a bit about each penguin species. Rather than show all three species when you open this slide, you might prefer to have the names come up one at a time.

You can do this using a feature xaringan calls incremental reveal . Place two dashes (–) between any content you want to display incrementally, like so:

This code lets you show Adelie onscreen first; then Adelie and Gentoo; and then Adelie, Gentoo, and Chinstrap. When presenting your slides, use the right arrow to incrementally reveal the species.

Aligning Content with Content Classes

You’ll also likely want to control how your content is aligned. To do so, you add the content classes .left[] , right[] , and center[] to specify the desired alignment for a piece of content. For example, to center-align the histogram, use .center[] as follows:

This code centers the chart on the slide.

Other built-in options can make two-column layouts. Adding .pull-left[] and .pull-right[] will make two equally spaced columns. Use the following code to display the histogram on the left side of the slide and the accompanying text on the right:

Figure  8.3 shows the result.

powerpoint presentations with r markdown

To make a narrow left column and wide right column, use the content classes .left-column[] and .right-column[]. Figure  8.4 shows what the slide looks like with the text on the left and the histogram on the right.

powerpoint presentations with r markdown

In addition to aligning particular pieces of content on slides, you can also horizontally align the entire content using the left , right , and center classes. To do so, specify the class right after the three dashes that indicate a new slide, but before any content:

This code produces a horizontally centered slide. To adjust the vertical position, you can use the classes top , middle , and bottom .

Adding Background Images to Slides

Using the same syntax you just used to center the entire slide, you can also add a background image. Create a new slide, use the classes center and middle to horizontally and vertically align the content, and add a background image by specifying the path to the image within the parentheses of url() :

To run this code, you’ll need a file called penguins.jpg in your project (you can download it at https://data.rfortherestofus.com/penguins.jpg ). Knitting the document should produce a slide that uses this image as a background with the text Penguins in front of it, as shown in Figure  8.5 .

powerpoint presentations with r markdown

Now you’ll add custom CSS to further improve this slide.

Applying CSS to Slides

One issue with the slide you just made is that the word Penguins is hard to read. It would be better if you could make the text bigger and a different color. To do this, you’ll need to use Cascading Style Sheets (CSS) , the language used to style HTML documents. If you’re thinking, I’m reading this book to learn R, not CSS , don’t worry: you’ll need only a bit of CSS to make tweaks to your slides. To apply them, you can write your own custom code, use a CSS theme, or combine the two approaches using the xaringanthemer package.

To add custom CSS, create a new code chunk and place css between the curly brackets:

This code chunk tells R Markdown to make the second-level header ( h2 ) 150 pixels large and white. Adding .remark-slide-content before the header targets specific elements in the presentation. The term remark comes from remark.js , a JavaScript library for making presentations that xaringan uses under the hood.

To change the font in addition to the text’s size and color, add this CSS:

The first new line makes a font called Inter available to the slides, because some people might not have the font installed on their computers. Next, this code applies Inter to the header and makes it bold. You can see the slide with bold Inter font in Figure  8.6 .

powerpoint presentations with r markdown

Because xaringan slides are built as HTML documents, you can customize them with CSS however you’d like. The sky’s the limit!

You may not care to know the ins and outs of CSS. Fortunately, you can customize your slides in two ways without writing any CSS yourself. The first way is to apply xaringan themes created by other R users. Run this code to get a list of all available themes:

The output should look something like this:

Some CSS files change fonts only, while others change general elements, such as text size, colors, and whether slide numbers are displayed. Using prebuilt themes usually requires you to use both a general theme and a fonts theme, as follows:

This code tells xaringan to use the default CSS, as well as customizations made in the metropolis and metropolis-fonts CSS themes. These come bundled with xaringan , so you don’t need to install any additional packages to access them. Figure  8.7 shows how the theme changes the look and feel of the slides.

powerpoint presentations with r markdown

If writing custom CSS is the totally flexible but more challenging option for tweaking your xaringan slides, then using a custom theme is simpler but a lot less flexible. Custom themes allow you to easily use others’ prebuilt CSS but not to tweak it further.

The xaringanthemer Package

A nice middle ground between writing custom CSS and applying someone else’s theme is to use the xaringanthemer package by Garrick Aden-Buie. This package includes several built-in themes but also allows you to easily create your own custom theme. After installing the package, adjust the css line in your YAML to use the xaringan-themer.css file like so:

Now you can customize your slides by using the style_xaringan() function. This function has over 60 arguments, enabling you to tweak nearly any part of your xaringan slides. To replicate the custom CSS you wrote earlier in this chapter using xaringanthemer , you’ll use just a few of the arguments:

This code sets the header size to 150 pixels and makes all the headers use the bold, white Inter font.

One particularly nice thing about the xaringanthemer package is that you can use any font available on Google Fonts by simply adding its name to header_font_family or another argument that sets font families ( text_font_family and code_font_family are the other two, for styling body text and code, respectively). This means you won’t have to include the line that makes the Inter font available.

In this chapter, you learned how to create presentations using the xaringan package. You saw how to incrementally reveal content on slides, create multi-column layouts, and add background images to slides. You also changed your slides’ appearance by applying custom themes, writing your own CSS, and using the xaringanthemer package.

With xaringan , you can create any type of presentation you want and then customize it to match your desired look and feel. Creating presentations with xaringan also allows you to share your HTML slides easily and enables greater accessibility.

Additional Resources

Garrick Aden-Buie and Silvia Canelón, “Professional, Polished, Presentable: Making Great Slides with xaringan,” workshop materials, n.d., https://presentable-user2021.netlify.app .

Silvia Canelón, “Sharing Your Work with xaringan: An Introduction to xaringan for Presentations: The Basics and Beyond,” workshop for the NHS-R Community 2020 Virtual Conference, November 2, 2020, https://spcanelon.github.io/xaringan-basics-and-beyond/index.html .

Alison Hill, “Meet xaringan: Making Slides in R Markdown,” slideshow presentation, January 16, 2019, https://arm.rbind.io/slides/xaringan.html .

Yihui Xie, J. J. Allaire, and Garrett Grolemund, “xaringan Presentations,” in R Markdown: The Definitive Guide (Boca Raton, FL: CRC Press, 2019), https://bookdown.org/yihui/rmarkdown/ .

Automate PowerPoint Production Using R

Joseph Noonan

February 17, 2021

One of the constants in my professional career is making graphs to put into PowerPoint presentations so that findings can be presented to other teams, partners, or clients. The difficultly with making PowerPoint presentations it is done manually and takes a ton of time. While R Markdown can allow streamlined workflows, it doesn’t always work in collaborative settings where PowerPoint is king. This is where the officer package comes to the rescue.

The goal for this post is to show you how to use for loops to automate graph production in ggplot2 and to take those graphs and put them into a PowerPoint deck with the officer package. This tutorial will be best suited to intermediate R users. You should be fairly comfortable with ggplot2 and the basics of loops or you might get lost when we start automating some of the processes.

This process can be broken down into 4 steps:

  • Get the data
  • Make a loop that makes the graphs
  • Prepare the PowerPoint
  • Make a loop that adds the graphs to the PowerPoint

The final product will be a single PowerPoint with a slide for each country showing the GDP annual % growth from 2009-2019.

At the end of the post, I’ll go through briefly another way of tackling this problem using functional programming instead of for loops.

All of the code used here is also avaiable on GitHub, including the PowerPoint materials

1. Get the data

To start with we are going to need to get some example data. Since I’ve always worked in the political science world, we are going to look at data from the World Bank. The wbstats package makes grabbing data from the World Bank’s database very easy.

Here I am grabbing the GDP annual % growth rate, only for countries (excluding regional classifications), between 2009 and 2019. You can change what indicators you want to pull by using the indicator argument. To find the indicator codes you can either use the function wb_search or just go to the World Bank’s online database and find it there. Since there are so many different indicators, I actually prefer using the web interface.

The result is a long dataset with a row for each indicator–country–year. In this case we are only working with one indicator but I still prefer working with long data since it works better with ggplot2 when graphing multiple indicators. Below, you can see how the dataset looks based on a random sample of rows. I have only included the most relevant variables.

indicator country iso3c date gdp_pct_growth
GDP per capita growth (annual %) Curacao CUW 2019 -0.0220876
GDP per capita growth (annual %) Mexico MEX 2017 0.0101582
GDP per capita growth (annual %) Japan JPN 2009 -0.0568145
GDP per capita growth (annual %) Tanzania TZA 2019 0.0265632
GDP per capita growth (annual %) Gibraltar GIB 2013 NA

2. Make a loop that makes the graphs

When I write loops to mass produce graphs, I follow a simple two step process: first, write the code to make the graphs, then figure out what actually need to change to make a the same graph but with different parameters This may seem simple, but I think for beginners it is important to break it down so you don’t get lost in trying to both learn how to do a task and automate it at the same time.

So, I will start with making a graph for a single country using the code below.

powerpoint presentations with r markdown

Now we have a very simple line chart of the GDP per captia growth in France from 2009-2019. The next step is making a chart like this for every country in the dataset, save that graph, and make a list of the file paths for all of these charts. This is where we are going to use a for loop. What for loops allow us to do is to repeat a task over and over again with different parameters. The first step in this process is to we need to first identify what parameters we will need to change for each graph. In this example there are three points where we have fill in, creating the dataset for the chart, the subtitle which mentions the country’s name, and the file name when we save our plot.

In this first step we are creating a list of countries which we will use to tell R what to iterate through. Here we are using the unique() function which will give us all of the unique values for the variable country in our dataset, that is to say, all unique country names.

Next, we are going to make a blank list. We will use this in our loop to create a list of file paths for all of the graphs we create. We will use this later when we build our PowerPoint decks with the officer package.

The next code chunk is the full for loop for creating and saving the graphs.

Here is how the loop works:

It starts by creating a data frame for the iteration. To do this we use the filter function to filter the dataset based on the country in country_list[i]

Next it creates the plot. The code here is almost identical to the the we used to make the the graph for France. The only difference is that we need to change the subtitle so that it changes based on the country the loop is iterating through. To do this we use the paste0 function, this allows us to concatenate strings pragmatically, so that we have both the country name and the years that it covers in the subtitle.

The next step is to create a file path and store it as object. Here we are using the paste0() function again. We first grab the working directory with getwd() , add in the subfolder ‘graphs’ and then lastly, name the image file. Here we are using the str_replace_all() function from the stringr package to remove all non-alphanumeric characters from the country names. Saving files with apostrophes or periods can often result in errors, so it is best to just avoid them completely. Once we have created our file path, we append it to the master lists of file paths that include all iterations in the loop.

Lastly, we save the graphs. Take note of the width and the height, as that is something we will need to be aware of when we prepare our PowerPoint.

The result is a graph for every country in our dataset saved to your hard drive and a list of file paths for each of those graphs ( file_path_list ).

3. Prepare the PowerPoint

When manipulating PowerPoints using the officer package, we need to create a ‘template’ PowerPoint deck, where we can specify the layout that we want our slides to have. In PowerPoint you do this through the ‘slide master’ view. If you don’t know how layouts in PowerPoint work, Microsoft provides a good overview of how they work . Since the titles of the graphs are in the image themselves, we can just make a new layout type with a content box that has the same dimensions as the graphs that we saved (7 inches by 5 inches). If the dimensions don’t match you’ll end up with some weird scaling and warping issues.

Here is what the template PowerPoint we will be working with looks like in the slide master view.

Once we have created PowerPoint template deck we can use read_pptx() to read in our PowerPoint into R.

Next, we can use the layout_summary() function to take a look at the different types of slide layouts we can use.

layout master
Title Slide Retrospect
Two Content Retrospect
Graph Retrospect

Here we have three different layouts, all from the same slide master “Retrsospect”. The custom slide that I have made is the layout “Graph”, while the other two are default layouts. We can take a closer look at the different elements with the “Graph” layout using layout_properties() .

master_name name type id ph_label
3 Retrospect Graph body 10 Content Placeholder 2
7 Retrospect Graph body 5 Rectangle 4
8 Retrospect Graph body 6 Rectangle 5

This table shows us the different elements in the “Graph” slide layout. The most important element is “Content Placeholder 2” which is where the graph will go in the slide. The two rectangle elements are just aesthetic elements in the footer of the slides.

4. Make a loop that adds the graphs to the PowerPoint

Now that we have the information about the layout of the PowerPoint template we can build our loop. We are going to be using four different functions from the officer package:

  • add_slide() - This function is fairly self explanatory, it adds a slide to a pptx object. In this case we have read in our pptx object as template_pptx .
  • ph_with() - This function adds a new shape or object into the existing slide. The two arguments will be using are value and location
  • external_img() - This function reads in a specified external image so that it can be embedded into a PowerPoint slide.
  • ph_location_label() . - This function is used in conjunction with ‘ph_with()’ to specify where an object should be added into the PowerPoint slide.

Something that is a bit confusing (for me at least) is how add_slide() adds a slide the to the specified PowerPoint and then overwrites the original PowerPoint object. I think this is best illustrated with an example.

I’ll start by looking at a summary of the blank PowerPoint template_pptx , using pptx_summary() .

Since there is are no slides, we get nothing returned. Now I’ll add one slide.

text id content_type slide_id
Test Title 1 2 paragraph 1

Now we have one slide containing only a title. If we were to rerun the code that we just ran, we would add the same slide again. It wouldn’t overwrite anything we just would have two of the same slides.

text id content_type slide_id
Test Title 1 2 paragraph 1
Test Title 1 2 paragraph 2

This is important to know both when for writing loops, but also when using the add_slide() function in general. You have to take extra care that your script is written in the order that you want the slides to appear, and when you are experimenting you need to be sure to clear out the pptx object by reading in the blank one so you don’t end up having a ton of ‘work in progress’ slides in your deck.

Now that we know how add_slide() works, it is time to write a loop. Before we used country_list to iterate through our loop but this time we are going to use the file_path_list that we created earlier. This is because the one parameter that we are changing is no longer country names, but rather where the image files are on our computer.

We start first by copying the template_pptx to a new object called gdp_growth_pptx . Because add_slide() is adding slides to the PowerPoint object, it is good to have a template object that you never change. The loop itself works in two steps. First read in saved ggplot2 image using external_img() then add it to the slides using add_slide() to specify the PowerPoint object and the layout, and ph_with() to specify what should be embedded and where it should be embedded in the slide.

The final product is single PowerPoint with a 217 slides, one for each country showing the GDP annual % growth from 2009-2019. To export this PowerPoint object you use the print() function.

This example is probably the simplest automation of PowerPoint reports you could make, only one paremeter changes when creating the graphs using ggplot2 and we are assuming that ther order doesn’t matter. However, this is a good starting point, reports with more complexity can be made using the techniques outlined in this post.

Bonus. Avoiding (some) loops by using the map function

For loops in R are often discouraged because they can be overly verbose and result in a ton of copying and pasting where small parameters are tweaked. An alternative approach to for loops is to use functionals like the map() functions from the purrr package. How these functions work is neatly summed up in the excellent book R for Data Science :

Each function takes a vector as input, applies a function to each piece, and then returns a new vector that’s the same length (and has the same names) as the input.

In our case we will create a custom function with the same parameters as the for loop we made in Step 2, this will be called country_graph() . Then we will use use the map() function, input our ‘country_list’ vector, and use country_graph() . The end result will give us a list of ggplot2 graphs, one for each country in our dataset.

Rewriting our loop as a function, isn’t super difficult. In practice, this means rewriting our code so that instead of using country_list[i] for the parameters that we need to change between iterations, we use x . This function has also been reworked so that we aren’t saving the files to the hard drive in this function, but rather just creating a ‘ggplot2’ plot.

We can use this function on it’s own if we want to make graphs for specific countries. This can be a practical alternative if you don’t need to create graphs for all of the different groups in a given dataset.

powerpoint presentations with r markdown

In the next step, we use map() to apply country_graph() to country_list and save those results as country_graph_list (please excuse my very creative naming conventions).

Now we have a a list of ggplot2 graphs. This means we can call the plots for each country by calling elements in the list.

powerpoint presentations with r markdown

To take this list and put all of the gglot2 graphs into a PowerPoint we use a similar loop as we used before, but this time we are a looping over the country_graph_list and instead of adding in external images, we are directly calling the ggplot2 object in the value parameter of ph_with() .

While this approach is more streamlined and seemingly simpler, the reason I prefer using external images is that the proportions and the ggplot2 are easier to control. When using this technique the titles and subtitles are much smaller in the PowerPoint and I am not sure the best way to fix that. But, like all things in R, I am sure there is just a solution I haven’t figured out yet.

  • Get started
  • About Lua filters
  • Version 2.7
  • Version 2.6

Convert to a PowerPoint presentation

Format for converting from R Markdown to a PowerPoint presentation. Pandoc v2.0.5 or above is required.

TRUE to include a table of contents in the output

Depth of headers to include in table of contents

TRUE to number section headings

TRUE to render slide bullets incrementally. Note that if you want to reverse the default incremental behavior for an individual bullet you can precede it with > . For example: > - Bullet Text . See more in Pandoc's Manual

Default width (in inches) for figures

Default height (in inches) for figures

TRUE to render figures with captions

Method to be used for printing data frames. Valid values include "default", "kable", "tibble", and "paged". The "default" method uses a corresponding S3 method of print , typically print.data.frame . The "kable" method uses the knitr::kable function. The "tibble" method uses the tibble package to print a summary of the data frame. The "paged" method creates a paginated HTML table (note that this method is only valid for formats that produce HTML). In addition to the named methods you can also pass an arbitrary function to be used for printing data frames. You can disable the df_print behavior entirely by setting the option rmarkdown.df_print to FALSE . See Data frame printing section in bookdown book for examples.

Keep the markdown file generated by knitting.

Markdown extensions to be added or removed from the default definition of R Markdown. See the rmarkdown_format for additional details.

The heading level which defines individual slides. By default this is the highest header level in the hierarchy that is followed immediately by content, and not another header, somewhere in the document. This default can be overridden by specifying an explicit slide_level .

Path to a PowerPoint template.

Additional command line options to pass to pandoc

R Markdown output format to pass to render()

  • Stack Overflow Public questions & answers
  • Stack Overflow for Teams Where developers & technologists share private knowledge with coworkers
  • Talent Build your employer brand
  • Advertising Reach developers & technologists worldwide
  • Labs The future of collective knowledge sharing
  • About the company

Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Get early access and see previews of new features.

R Markdown PowerPoint Slide Customization

default slide

I'm reading R Studio's guide to creating PowerPoint presentations in R Markdown . I'd like to be able to customize my slides to include two things:

  • Stretch the image size to the full width of the slide
  • Move the title up a bit and left align it

After doing some internet searches I just can't determine how to do this properly. Maybe you know how. Here's what I'm looking for (image below). Adjusting the output width doesn't seem to help much.

desired slide

You can adjust the layout of the resulting powerpoint file by creating a "reference" powerpoint file that has custom master slide layouts that you create. The Templates section of the RStudio document you linked to explains how to do this.

The basic idea is to open a new powerpoint file and customize the master slide styles, or use an existing powerpoint document or template that either already has the styles you want or that can be tweaked to get what you want. Save that customized file in your RStudio project folder (or to some other path that you can reference in the YAML header) and then reference it in the YAML header. If this reference document is called my_template.pptx , then the YAML header would look like this:

For your case, I knitted the document you provided to a file called test.pptx and used that as my starting document to create the desired template. After opening that document, I opened the "slide master":

enter image description here

This brings up the following view:

enter image description here

Click on Insert Layout (near left end of ribbon) to create a new slide layout, which will become our edge-to-edge picture layout. Then click on the Insert Placeholder dropdown and select Picture . Then click-drag to add an edge-to-edge picture placeholder in the slide layout we just created. You can also move the slide title box higher and, using the Home menu, set it to be left-justified. The new slide layout now looks like this:

enter image description here

Click Slide Master (left end of ribbon) and then click Close Master (on the right end of the ribbon). Then save the file as my_template.pptx .

Now compile the following document:

And this is what the powerpoint slide looks like:

enter image description here

That's not quite what we wanted. Let's try a different aspect ratio of fig.asp=0.5 :

enter image description here

That's better, although the resolution is poor. So let's set the dpi chunk argument so that the chunk header is now the following:

which gives us the following powerpoint slide with much sharper lines and text:

enter image description here

Your Answer

Reminder: Answers generated by artificial intelligence tools are not allowed on Stack Overflow. Learn more

Sign up or log in

Post as a guest.

Required, but never shown

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy .

Not the answer you're looking for? Browse other questions tagged r r-markdown powerpoint officer or ask your own question .

  • Featured on Meta
  • Upcoming sign-up experiments related to tags
  • The return of Staging Ground to Stack Overflow
  • Policy: Generative AI (e.g., ChatGPT) is banned
  • Should we burninate the [lib] tag?

Hot Network Questions

  • Better to edit $VIMRUNTIME/filetype.vim or add a script in $HOME/vimfiles/ftdetect?
  • Weapon in The Peacemaker
  • New faculty position – expectation to change research direction
  • Should mail addresses for logins be stored hashed to minimize impact of data loss?
  • Why did Geordi have his visor replaced with ocular implants between Generations and First Contact?
  • Cut and replace every Nth character on every row
  • How do Blok and the other astronaut do a spacewalk to repair the ship? Didn’t they already land?
  • A class for students who want to get better at a subject, aside from their public education
  • How does a vehicle's brake affect the friction between the vehicle and ground?
  • Historically are there any documented attempts at finding algorithms that are asymptotically faster than the FFT for the Discrete Fourier Transform?
  • Idiom for a situation where a problem has two simultaneous but unrelated causes?
  • What does "acceptable" refer to in Romans 12:2?
  • How to join two PCBs with a very small separation?
  • Binary Slashes Display
  • Vespertide affairs
  • Styling histograms
  • How do I pour *just* the right amount of plaster into these molds?
  • Is this professor being unnecessarily harsh or did I actually make a mistake?
  • Are 1/20 undocumented immigrants married to American citizens?
  • Could Kessler Syndrome be used to control the temperature of the Earth?
  • What should a content person pray for?
  • How to make sure to only get full frame lenses for the Canon EF (non-mirrorless) mount?
  • Exception handling: 'catch' without explicit 'try'
  • A chess engine in Java: generating white pawn moves

powerpoint presentations with r markdown

rmarkdown Dynamic Documents for R

  • Package overview
  • Learn R Markdown
  • Lua filters in R Markdown
  • all_output_formats: Determine all output formats for an R Markdown document
  • available_templates: List available R Markdown template in a package
  • beamer_presentation: Convert to a Beamer presentation
  • compile_notebook: Compiling R scripts to a notebook
  • context_document: Convert to a ConTeXt document
  • convert_ipynb: Convert a Jupyter/IPython notebook to an R Markdown document
  • default_output_format: Determine the default output format for an R Markdown...
  • draft: Create a new document based on a template
  • find_external_resources: Find External Resource References
  • find_pandoc: Find the 'pandoc' executable
  • github_document: Convert to GitHub Flavored Markdown
  • html-dependencies: Provide common HTML dependencies for R Markdown formats
  • html_document: Convert to an HTML document
  • html_document_base: Base output format for HTML-based output formats
  • html_fragment: Convert to an HTML fragment.
  • html_notebook: Convert to an HTML notebook
  • html_notebook_metadata: Generate R Notebook Metadata
  • html_notebook_output: Generate R Notebook Output
  • html_vignette: Convert to an HTML vignette
  • includes: Include content within output
  • ioslides_presentation: Convert to an ioslides Presentation
  • knit_params_ask: Run a shiny application asking for parameter configuration...
  • knitr_options: Knitr options for an output format
  • knitr_options_html: Knitr options for an HTML output format
  • knitr_options_pdf: Knitr options for a PDF output format
  • latex-dependencies: Provide common LaTeX dependencies
  • latex_dependency: Define a LaTeX package dependency
  • md_document: Convert to a markdown document
  • metadata: The YAML metadata of the current R Markdown document
  • navbar_html: Create a navbar HTML file from a navbar definition
  • odt_document: Convert to an OpenDocument Text (ODT) document
  • output_format: Define an R Markdown output format
  • output_format_dependency: Define and merge an R Markdown's output format dependency
  • output_metadata: The output metadata object
  • paged_table: Create a table in HTML with support for paging rows and...
  • pandoc_args: Functions for generating pandoc command line arguments
  • pandoc_available: Check pandoc availability and version
  • pandoc_citeproc_convert: Convert a bibliograpy file
  • pandoc_convert: Convert a document with pandoc
  • pandoc_exec: Get the path of the pandoc executable
  • pandoc_options: Pandoc options for an output format
  • pandoc_path_arg: Transform path for passing to pandoc
  • pandoc_self_contained_html: Create a self-contained HTML document using pandoc.
  • pandoc_template: Render a pandoc template.
  • parse_html_notebook: Parse an HTML Notebook
  • pdf_document: Convert to a PDF/LaTeX document
  • pkg_file_lua: Get the full paths of Lua filters in an R package
  • powerpoint_presentation: Convert to a PowerPoint presentation
  • publish_site: Publish an R Markdown Website
  • relative_to: Relative path utility function
  • Browse all...

powerpoint_presentation : Convert to a PowerPoint presentation In rmarkdown: Dynamic Documents for R

View source: R/powerpoint_presentation.R

powerpoint_presentationR Documentation

Convert to a PowerPoint presentation

Description.

Format for converting from R Markdown to a PowerPoint presentation. Pandoc v2.0.5 or above is required.

to include a table of contents in the output

Depth of headers to include in table of contents

to number section headings

to render slide bullets incrementally. Note that if you want to reverse the default incremental behavior for an individual bullet you can precede it with . For example: . See more in

Default width (in inches) for figures

Default height (in inches) for figures

to render figures with captions

Method to be used for printing data frames. Valid values include "default", "kable", "tibble", and "paged". The "default" method uses a corresponding S3 method of , typically . The "kable" method uses the function. The "tibble" method uses the tibble package to print a summary of the data frame. The "paged" method creates a paginated HTML table (note that this method is only valid for formats that produce HTML). In addition to the named methods you can also pass an arbitrary function to be used for printing data frames. You can disable the behavior entirely by setting the option to . See in bookdown book for examples.

Keep the markdown file generated by knitting.

Markdown extensions to be added or removed from the default definition of R Markdown. See the for additional details.

The heading level which defines individual slides. By default this is the highest header level in the hierarchy that is followed immediately by content, and not another header, somewhere in the document. This default can be overridden by specifying an explicit .

Path to a PowerPoint template.

Additional command line options to pass to pandoc

R Markdown output format to pass to render()

Related to powerpoint_presentation in rmarkdown ...

R package documentation, browse r packages, we want your feedback.

powerpoint presentations with r markdown

Add the following code to your website.

REMOVE THIS Copy to clipboard

For more information on customizing the embed code, read Embedding Snippets .

Navigation Menu

Search code, repositories, users, issues, pull requests..., provide feedback.

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly.

To see all available qualifiers, see our documentation .

  • Notifications You must be signed in to change notification settings

powerpoint_presentation.R

Latest commit, file metadata and controls.

You are now being redirected to mayfile.online....

IMAGES

  1. Create PowerPoint Presentations with R and RMarkdown

    powerpoint presentations with r markdown

  2. Make PowerPoint Presentations with R Markdown

    powerpoint presentations with r markdown

  3. How To Make A PowerPoint Presentation Using R Markdown

    powerpoint presentations with r markdown

  4. Create PowerPoint Presentations with R and RMarkdown

    powerpoint presentations with r markdown

  5. Create PowerPoint Presentations with R and RMarkdown

    powerpoint presentations with r markdown

  6. How To Make A PowerPoint Presentation Using R Markdown

    powerpoint presentations with r markdown

VIDEO

  1. Powerpoint Blackbelt #10 Grab Your Audience Attention with Simple yet Dynamic Animated Charts

  2. How to improve your PowerPoint Presentation Slides🤔😍😎

  3. Importance of PowerPoint| Lesson 02| Professional Presentation

  4. Apresentações Automáticas com o R

  5. AM Coder

  6. An R Markdown Template for Beamer Presentations 1

COMMENTS

  1. 4.4 PowerPoint presentation

    The first official book authored by the core R Markdown developers that provides a comprehensive and accurate reference to the R Markdown ecosystem. With R Markdown, you can easily create reproducible data analysis reports, presentations, dashboards, interactive applications, books, dissertations, websites, and journal articles, while enjoying the simplicity of Markdown and the great power of ...

  2. How To Make A PowerPoint Presentation Using R Markdown

    Once in RStudio, go to File - New File - R Markdown. A window like the one below should appear: Image 1 - Creating a new R Markdown PowerPoint Presentation. Give your presentation a title and optionally specify the author. Also, make sure to select PowerPoint as the default output format.

  3. Slide Presentations

    Turn your analyses into high quality documents, reports, presentations and dashboards with R Markdown. Use a productive notebook interface to weave together narrative text and code to produce elegantly formatted output. Use multiple languages including R, Python, and SQL. R Markdown supports a reproducible workflow for dozens of static and dynamic output formats including HTML, PDF, MS Word ...

  4. Rendering PowerPoint Presentations with the RStudio IDE

    Getting Started. To create a PowerPoint presentation, open a new R Markdown PowerPoint presentation or specify powerpoint_presentation as an output format in the YAML header. New File > R Markdown > Presentation > PowerPoint. When you knit an R Markdown document, RStudio renders your document in the PowerPoint output format.

  5. How To Make A PowerPoint Presentation Using R Markdown

    We assume you have R and RStudio installed. Once in RStudio, go to File - New File - R Markdown. A window like the one below should appear: Image 1 - Creating a new R Markdown PowerPoint Presentation Give your presentation a title and optionally specify the author. Also, make sure to select PowerPoint as the default output format.

  6. rmarkdown: Make interactive PowerPoint slide presentations in R

    Slide Decks are so important for #storytelling in business. We can use #Rmarkdown to tell our story with engaging interactivity. Here's how to make Interacti...

  7. Nathan Stephens

    Data scientists use R Markdown documents to create reproducible code that can be rendered in a variety of output types. Some of the most common output types ...

  8. Use patchwork and R Markdown for multi-image slide layouts in PowerPoint

    First, create a new R Markdown document and specify powerpoint_presentation as the output format in the YAML header: --- title: "Multi-image slide layouts in PowerPoint via R Markdown" author: "Matt Herman" output: powerpoint_presentation: reference_doc: template.pptx ---. If you want to use a PowerPoint template, you can specify a reference ...

  9. How to create PowerPoint slides from R

    To create a PowerPoint from R, you need three things on your system: PowerPoint or OpenOffice, The rmarkdown package, version 1.9 or later, and. Pandoc version 2.0.5 or newer. Pandoc isn't an R ...

  10. Create PowerPoint Presentations with R and RMarkdown

    Make sure that this document compiles and gives you a nice PowerPoint presentation. Click on the "knit" button. Save your file. If everything works out, you should have a new PowerPoint presentation. If everything worked out, edit the RMarkdown document with the new content for this streaming services presentation.

  11. Mastering R presentations

    How to start. The first step is to get R and RStudio, and install the package rmarkdown with the code. install.packages("rmarkdown") In the last versions you can directly create presentations going to File -> New File -> R Presentation.Then, a .RPres document is going to be created. This is the simplest, really simplest, way to start but my advice is to go quickly to the next step if you want ...

  12. How to Create PowerPoint Presentations using RMarkdown and ...

    In this video, you will learn how to create PowerPoint presentations using R and RMarkdown. You can create HTML and PDF presentation options using RMarkdown ...

  13. Chapter 4 Presentations

    The first official book authored by the core R Markdown developers that provides a comprehensive and accurate reference to the R Markdown ecosystem. With R Markdown, you can easily create reproducible data analysis reports, presentations, dashboards, interactive applications, books, dissertations, websites, and journal articles, while enjoying the simplicity of Markdown and the great power of ...

  14. R for the Rest of Us: A Statistics-Free Introduction

    Next, navigate to File > New File > R Markdown to create a new project. Choose the From Template tab and select the template called Ninja Presentation, then click OK. You should get an R Markdown document containing some default content. Delete this and add the penguin R report you created in Chapter 6.

  15. Make PowerPoint Presentations with R Markdown

    41:55. Data scientists use R Markdown documents to create reproducible code that can be rendered in a variety of output types. Some of the most common output types include HTML, Word, and PDF, but new improvements make it possible to create PowerPoint presentations as well. PowerPoint presentations are still common currency for sharing insights ...

  16. Joseph Noonan

    The difficultly with making PowerPoint presentations it is done manually and takes a ton of time. While R Markdown can allow streamlined workflows, it doesn't always work in collaborative settings where PowerPoint is king. This is where the officer package comes to the rescue.

  17. Render PowerPoint presentations from R Markdown documents

    Note: If you want to change the slide size or design you should make those changes in a PowerPoint template and then include reference_doc: mytemplate.pptx in the YAML header. About Render PowerPoint presentations from R Markdown documents

  18. Convert to a PowerPoint presentation

    Source: R/powerpoint_presentation.R. powerpoint_presentation.Rd. Format for converting from R Markdown to a PowerPoint presentation. Pandoc v2.0.5 or above is required. ... rmarkdown is built for R Markdown, an ecosystem of packages for creating computational documents in R. Learn more at rmarkdown.rstudio.com.

  19. R Markdown PowerPoint Slide Customization

    This brings up the following view: Click on Insert Layout (near left end of ribbon) to create a new slide layout, which will become our edge-to-edge picture layout. Then click on the Insert Placeholder dropdown and select Picture. Then click-drag to add an edge-to-edge picture placeholder in the slide layout we just created.

  20. powerpoint_presentation : Convert to a PowerPoint presentation

    In addition to the named methods you can also pass an arbitrary function to be used for printing data frames. You can disable the df_print behavior entirely by setting the option rmarkdown.df_print to FALSE. See Data frame printing section in bookdown book for examples. Keep the markdown file generated by knitting.

  21. rmarkdown/R/powerpoint_presentation.R at main

    History. Code. 109 lines (95 loc) · 3.61 KB. #' Convert to a PowerPoint presentation #' #' Format for converting from R Markdown to a PowerPoint presentation. Pandoc #' v2.0.5 or above is required. #' @inheritParams pdf_document #' @inheritParams html_document #' @inheritParams beamer_presentation #' @param reference_doc Path to a PowerPoint ...

  22. PDF Creating Dynamic Powerpoint Presentations

    R Markdown Yihui Xie,J.J. Allaire,Garrett Grolemund,2018-07-27 R Markdown: The Definitive Guide is the first official book authored by the core R Markdown developers that provides a comprehensive and accurate reference to the R Markdown ecosystem. With R Markdown, you can easily create reproducible data analysis reports, presentations,