- It seems we can’t find what you’re looking for. Perhaps searching can help.
- WELLCOME FORUM SENDI Forum berbagi info teknologi & sejarah.
There are many ways to create presentations with R Markdown. The package xaringan build by Rstudio employee Yihui Xie is one possiblity to create impressionable HTML5 slides that really stand out. It’s beautiful layout and concise and tidy coding structure makes it a charm to work with. It’s build on the remark.js library and if you want to learn more about it you can do this here. Here are some example slides by the creator which also serves as an introduction:
Are you ready to become a presentation ninja?
There is multiple ways to install packages in R. One safe bet is to install the xaringan package from CRAN, as follows:
Sometimes the versions on CRAN are somewhat older. If you are interested in the newest version, one option is to always look for the related (GitHub) repository. To install it from here you need to first install the devtools package in case you don’t have it and then use install_github(“yihui/xaringan”) to install the package from GitHub.
To create a xaringan presentation, you create an R Markdown document with the xaringan::moon_reader output format. From within RStudio, it is easy to get started. First click on the New File icon below File and then on R Markdown:
Next select “From Template” then Ninja Presentation, and you will see an R Markdown example.
Press the Knit button to compile it.
As is the norm with any R Markdown document, there is a yaml header at the beginning which specifies some meta data. Here you can put in the title of the presentation, authors and more. This will configure the title slide. Much more can be done here to customize how your slides will look like but for now we stick with the basics. Here is how your yaml header could look like:
This gives us the following title slide:
So how are slides created with xaringan? Easy!
Overall, regular R Markdown rules apply so you can use this for italic and two stars for bold for example or even your most complicated LaTeX equations.
The # before a line of text creates a header for the slide and the more hashtags you add the smaller is the header
Slides are then seperated with three lines
---. For the first slide you don’t need to do this because it is already implied after the yaml header.
If we wanted to let elements on the slides appear with a click, we seperate them with two lines
-- like this.
Lastly, if we want to have more space between the elements on a slide we can use the html tag
You could start with something like this:
This is how this would look like:
This looks awesome already!
Let’s say we want to play around a bit with the format of our slides. There are some build in functions that lets us do exactly that.
We specify the following code at the beginning of a slide:
class: inverse, center, middle
This will inverse the color (here: black) center the elements horizontally (center) and vertically (middle) on that slide. This makes for some pretty cool transition slides.
Here is an example:
Which produces the following slide:
Adding a GIF or an Image
You can also add GIFs or images to your slides. It’s done exactly in the same way as you would with a normal R Markdown document. Here is an example:
using themes and xaringanthemer
We’ve already come a long way creating nice xaringan slides. If we wanted to customize the theme of the presentation, xaringan comes with some build-in color schemes that you can try out.
Here is one of them. Just add the following line in your YAML header and you are good to go:
This looks like this:
Here is a list of themes:
If you want to create your own themes I can recommend the xaringanthemer package:
Exporting the presentation to .pdf
The output format of xaringan is html. However, if you want a .pdf file you could just simply open the slides in your favorite web browser and print them to .pdf. This seems to be the easiest version to do it.
I hope you enjoyed this little tutorial!
Here are some more examples of beautiful xaringan slides that can serve as your inspiration:
You want to add animated transitions? Well, here’s an implementation of that:
Lastly, a wiki helps to implement more advanced options. Be sure to check it out at some point:
tsukuyomi() is an alias of
A vector of CSS file paths. Two default CSS files(
default-fonts.css) are provided in thispackage, which was borrowed from https://remarkjs.com. If thecharacter vector
css contains a value that does not end with
.css, it is supposed to be a built-in CSS file in this package,e.g., for
css = c('default', 'extra.css')), it means
default.css in this package and a user-provided
extra.css. Tofind out all built-in CSS files, use
Whether to produce a self-contained HTML file byembedding all external resources into the HTML file. See the ‘Note’section below.
Whether to generate a title slide automatically using the YAMLmetadata of the R Markdown document (if
FALSE, you should write thetitle slide by yourself).
Whether to insert theMustache Karl (TM) randomly in the slides.
TRUE means insert his picture onone slide, and if you want him to be on multiple slides, set
yolo toa positive integer or a percentage (e.g. 0.3 means 30% of your slides willbe the Mustache Karl). Alternatively,
yolo can also be a list of theform
list(times = n, img = path):
n is the number of times toshow an image, and
path is the path to an image (by default, it isKarl).
A path to the remark.js library (can be either local orremote). Please note that if you use the default remote latest version ofremark.js, your slides will not work when you do not have Internet access.They might also be broken after a newer version of remark.js is released.If these issues concern you, you should download remark.js locally (e.g.,via
summon_remark()), and use the local version instead.
(Nature transformation) A list of configurations to be passedto
list(ratio = '16:9', navigation =list(click = TRUE)); seehttps://github.com/gnab/remark/wiki/Configuration. Besides theoptions provided by remark.js, you can also set
autoplay to a number(the number of milliseconds) so the slides will be played every
autoplay milliseconds; alternatively,
autoplay can be a listof the form
list(interval = N, loop = TRUE), so the slides will goto the next page every
N milliseconds, and optionally go back to thefirst page to restart the play when
loop = TRUE. You can also set
countdown to a number (the number of milliseconds) to include acountdown timer on each slide. If using
autoplay, you can optionallyset
TRUE to include a countdown equal to
autoplay. To alter the set of classes applied to the title slide,you can optionally set
titleSlideClass to a vector of classes; thedefault is
c('center', 'middle', 'inverse').
Xaringan R House
tsukuyomi(), arguments passed to
moon_reader(), arguments passed to
Tsukuyomi is a genjutsu to trap the target in an illusion on eye contact.
If you are unfamiliar with CSS, please see thexaringan wiki on Githubproviding CSS slide modification examples.