You can now reuse your code from that R Markdown document and use it to make figures, tables, and more in your xaringan slides. Say you’ve written a report that you’ve knitted to a Word document. In my conversation with Silvia Canelón, she brought up three main reasons.įirst, if you’re already working in R and R Markdown, being able to produce slides in the same tool is a game changer. Now that we’ve discussed how to use xaringan, let’s talk a bit about why you might consider switching to it for your presentations. In Conclusion: The Advantages of xaringan This code tells xaringan to use the default CSS as well as customizations made in the metropolis and metropolis-fonts CSS files (these come bundled with xaringan so you don’t need to do anything beyond installing the package to access them). To use the theme, you adjust your YAML as follows. You can then choose a theme you’d like to use. remark-slide-content before the h2 in order to make sure we target the specific element in our presentation (remark comes from remark.js, a JavaScript library to make presentations that xaringan uses under the hood).ĭoing this will show the following output: #> "chocolate-fonts" "chocolate" I can then add CSS like this to tell R Markdown to make the h2 (the second-level header) 150px and white. To tell R Markdown that this code chunk contains CSS, not R, I put the text “css” in between the curly brackets. To add custom CSS, I’m going to create a code chunk. You just have to know a bit of CSS to make tweaks to your slides. If you’re thinking, “I’m reading this book to learn R, not CSS,” don’t worry. To do this, we need to use some CSS, the language used to style HTML documents (remember, when we knit our xaringan presentation, we end up with an HTML document). One issue with the slide we just made is that it’s hard to read the word “Penguins.” It would probably be best if we could make the text bigger and a different color. If I open up the HTML document, I see Figure 9.3. When I hit Knit, I get an HTML file with the same name as R Markdown document (in my case, xaringan-example.Rmd and xaringan-example.html). Let’s try hitting the Knit button to see what it looks like. With this change, we will now get slides rather than a Word document. Instead of output: word_document we now have output: xaringan::moon_reader. This code should look familiar because it is exactly the same as the R Markdown document we created in Chapter 7 with one line changed in the YAML. The average bill length is `r average_bill_length` millimeters. title: "Penguins Report" author: "David Keyes" date: "" output: xaringan::moon_reader - ``` average_bill_length % summarize(avg_bill_length = mean(bill_length_mm, na.rm = TRUE)) %>% pull(avg_bill_length) ``` The chart shows the distribution of bill lengths. As you’ll hear in this chapter, these benefits include, but also go well beyond, making good-looking slides. Canelón has done extensive teaching on the xaringan package and has thought deeply about its benefits. To learn more about the capabilities of xaringan, I spoke with Silvia Canelón, a data analyst in the Urban Health Lab at the University of Pennsylvania. This package, which uses R Markdown to make presentations, is one of several you can use to make slides, but it is the most widely used. In this chapter, we’ll learn how to make presentations in R using the xaringan package. Do you need to do your analysis, data visualization, and table making in R and then copy everything to PowerPoint by hand? No! R has robust presentation-making capabilities. You may be wondering at this point if creating presentations will require us to add another tool, like PowerPoint. In Chapter 7, we talked about the R Markdown-based workflow having the benefit of keeping everything in one tool. Reporting happens in presentations as often as it does in Word-based reports. Remember how we talked in Chapter 7 about the multi-tool workflow from SPSS to Excel to Word? That leaves out one of the most common tools in many people’s workflow: PowerPoint. The size can be adjusted using the style="" part below.9 Create Beautiful Presentations with R Markdown The html file contains the following, which uses an image called logo.png. In the example below, I used an external html file called Logo_prefix.html, which is referenced in the includes: section of the YAML header. We can get what we want with a little html and some YAML options. Logos, for example, which are so common (and necessary) in presentations, are not included by default and can be tricky and annoying to include. revealjs gives you really slick options for presentations, but can be a lot of extra work in terms of customizing the output. The image of the two columns above was part of a revealjs presentation done in R Markdown. Will make 'variable_1' appear in code-style text and be blue ( variable_1), whereas '?dplyr::select' will be bold and 70% of the size that it would otherwise be.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |