options(htmltools.dir.version = FALSE) knitr::opts_chunk$set( warning = FALSE, message = FALSE, fig.showtext = TRUE ) library(tidyverse) library(unhcrthemes) library(fontawesome)
html_slides
is a simple online presentation template which is part of the unhcrdown
package.
Install the unhcrdown
package from Github:
# If pak is not yet installed, uncomment the following line: # install.packages("pak") pak::pkg_install("unhcr-dataviz/unhcrdown")
Main resources:
unhcrdown::html_slides
vignettexaringan
slidesremark.js
slidesunhcrthemes
packageThe default YAML arguments are below, but not all the YAML arguments are mandatory so change it accordingly.
--- title: "Main presentation title" subtitle: "Subtitle if needed" author: "Your name" institute: "Bureau/Divisions" date: "`r format(Sys.Date(), '%d %B %Y')`" output: unhcrdown::html_slides: self_contained: true nature: highlightStyle: github highlightLines: true countIncrementalSlides: false ratio: "16:9" ---
All the arguments, coming after the unhcrdown::html_slides
call, are part of the xaringan package.
See the help page ?xaringan::moon_reader
for all possible configurations.
name: shortcut
Press h or ? to see the remark.js
keyboard shortcuts, to help you navigate your presentation.
If you have two screens, a common workflow is to:
Press c to clone your presentation
On the presentation screen: Move cloned window here, then press f for full-screen mode
On the extra screen: Press p for presenter mode. See below to learn how to add presenter notes
name: basic-slide
.pull-left[ - Slide content starts immediately after the YAML ends
Use 3 dashes in a row ---
on a line by itself to create a new slide
Use 2 dashes in a row --
for incremental content
.pull-right[
--- title: "Main presentation title" output:unhcrdown::html_slides --- # Slide one Lorem ispum... ??? Notes on slide 1 --- # Slide Two Lorem ispum...
]
??? Only you will see this when in presenter mode.
As mentioned in Basic slides use 2 dashes in a row --
for incremental content.
--
--
--
You can use the following classes to align content within a slide:
left
, center
, right
top
, middle
, bottom
--- class: center, middle
Or you can align specific text, horizontal only
.right[this text will be on the right]
.right[this text will be on the right]
No class added as default behavior
class: center
Apply to whole slide content
class: center, right
Apply to whole slide content
class: middle
Apply to whole slide content
class: middle, center
Apply to whole slide content
class: middle, right
Apply to whole slide content
class: bottom
Apply to whole slide content
class: bottom, center
Apply to whole slide content
class: bottom, right
Apply to whole slide content
You can move content to the left or right using the following classes .pull-left[]
and .pull-right[]
.
This will create a two-column layout, where each column takes up to 47% of the page width.
All the column content needs to go within the respective []
.
.pull-left[ Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. ]
.pull-right[ Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. ]
You can even go back to the entire width if you need the two columns only for a certain portion of the slide.
The layout classes are really helpful and can create complex layout by nesting them.
.pull-left[ .pull-left[
This is a .pull-left[]
within a .pull-left[]
]
.pull-right[
This is a .pull-right[]
within a .pull-left[]
]
]
.pull-right[ .pull-left[
This is a .pull-left[]
within a .pull-right[]
]
.pull-right[
This is a .pull-right[]
within a .pull-right[]
]
]
.left-column[
I am a narrow column that leaves a lot of space for my bigger .right-column[]
friend.
I come with a lighter font colour. ]
.right-column[
You can similarly use .left-column[]
and .right-column[]
, the sizes are then 20% and 75%.
I am a really wide column and I keep my font colour.
This layout is useful to draw attention to the main content on the right side and keeping the left side as an aside.
It is a specific layout and should be only use sporadically, e.g. showing a big picture on the right side.
Unlike .pull-left[]
and .pull-right[]
these columns are meant to be used for the entire slide. You avoid avoid adding content outside the respective []
.
]
The template comes with predefined styles for inline text, such as italic, bold or underline text.
It also includes the required styles for common elements such as:
.pull-left[ Headers:
Lists:
.pull-right[
Quotes:
It is further proof that refugee movements and the broader issue of migration of populations ... is a global challenge that cannot be confined to a few countries.
Filippo Grandi
Footnotes:
Footnotes are created using the .footnote[]
class outside of the column.
]
.footnote[
This is a footnote can be tied to a number in the main text using the <sup>
html tag
]
.pull-left[
You can change the size of the text by using the .large[]
or .small[]
class
.large[Large text] followed by .small[small text] example
You can change the colour of the text by using the .blue[]
or .grey[]
class
.blue[Blue text] followed by .grey[grey text] example
You can change the background of the text by using the .bg-blue[]
or .bg-grey[]
class
Some of this text will be in a .bg-blue[blue background]
Some of this text will be in a .bg-grey[grey background] ]
--
.pull-right[ You can also create a call out box by wrapping the entire content with the background class.
.bg-blue[ I will become a text box with background! ]
.bg-blue[
I will become a text box with background!
] ]
.pull-left[ Depending on your need and control over the image output you can use the following approaches to include images in your slides:

knitr::include_graphics("path_to_image")
<img src="path_to_image" width="90%"/>
Inline R Markdown scale depends on the image size. To control the size use knitr
or html
:
# set out.width="50%" code chunk parameter # don't forget echo=FALSE to see only the image knitr::include_graphics("path_to_image")
]
.pull-right[ .center[
knitr::include_graphics("https://raw.githubusercontent.com/vidonne/unhcrdown/master/inst/resources/img/cover-example.jpg")
] ]
The brand unit recommends using the Humanitarian icons which are now part of the Fontawesome set.
To directly access Fontawesome in R, simply install and load the fontawesome
R package.
.pull-left[
# install.packages('fontawesome') library(fontawesome) .blue[`r fa("hands-holding-circle")`]
]
.pull-right[
.large[.blue[r fa("hands-holding-circle")
] Protection]
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. ]
The default slide background is white but you can apply a branded UNHCR blue by adding the class inverse
to the slide.
The font colours will adapt automatically.
This can be useful to create a section break in your presentation.
The inverse
class can be coupled with the alignment classes.
Code for next slide:
--- class: inverse, center, middle # My new section ### Be descriptive
class: inverse, center, middle
You can specify a background image (or multiple images) at the start of your slide, just like you set the class for the background colour:
--
background-image: url(path_to_image)
--
background-size
:cover
: Scales the image (while preserving its ratio) to the smallest possible size to fill the container.contain
: Scales the image as large as possible within its container without cropping or stretching the image.--
background-position
: see here for different options.--
inverse
class of the slide depending on the logo colour that works better with your picture.--
hide-logo
class.class: hide-logo background-image: url(https://raw.githubusercontent.com/vidonne/unhcrdown/master/inst/resources/img/cover-example.jpg) background-size: cover background-position: center 25%
class: inverse, center, middle
.pull-left[
To highlight lines of code simply add #<<
at the end of each targeted row and a light yellow background will be added.
]
.pull-right[
library(tidyverse) mtcars_select <- mtcars |> select(hp, mpg, cyl) #<< glimpse(mtcars_select)
]
--
.pull-left[
It is also possible to highlight the code output by adding highlight.output = c(3,4)
to the code chunk options.
]
.pull-right[
library(tidyverse) mtcars_select <- mtcars |> select(hp, mpg, cyl) #<< glimpse(mtcars_select)
]
.pull-left[
- We recommend the use of kable
from the knitr package.
Make sure to add the format HTML to your kable
call: knitr::kable(format = "html")
..small[1]
See here more information on kable
and what it can do, like formatting numbers , changing column, etc.
For more flexibility and advanced table style refer to other R packages like GT
or DT
.
]
.pull-right[
head(mtcars_select) |> knitr::kable(format = "html", col.names = c("Fuel efficiency", "Horsepower", "Num. of cylinder"), caption = "Subset of mtcars dataset")
]
.footnote[
1You can also set this as a global option for all your slides using options(knitr.table.format = "html")
.
]
For simple tables, we included a series of classes that can be applied to kable
output format. Simply add the required class names to the table.attr
parameter of the kable
call, don't forget to use \
to escape the quote character.
.pull-left[ The following classes are available:
.table
: initiate the possibility to stylize the table and provide base style. This class is mandatory.
.table-blue
: add blue background for alternate rows.
.table-grey
: add grey background for alternate rows.
.table-narrow
: fit the table width to the content.
.table-noborder
: remove all borders from the table.
]
.pull-right[
head(mtcars_select) |> knitr::kable(format = "html", col.names = c("Fuel efficiency", "Horsepower", "Num. of cylinder"), caption = "Subset of mtcars dataset", table.attr = "class=\"table table-blue table-noborder\"")
]
For the creation of charts, we recommend using the unhcrthemes
as it provides a ggplot2
theme and a set of colour palettes for making charts and graphics.
.pull-left[
For more information on how to make a plot using unhcrthemes
please refer to package documentation and the UNHCR Data Visualization Platform R tutorials.
Getting your plot right is not always easy, but you can control your plots by playing with individual chunk options like fig.retina
and out.width
(plus fig.width
and fig.height
).
]
.pull-right[
ggplot( mtcars, aes(x = hp, y = mpg, color = as.factor(cyl)) ) + geom_point(alpha = .8) + labs( title = "Simple scatterplot with ggplot", subtitle = "This plot shows the default style of theme_unhcr()", x = "Horsepower (hp)", y = "Fuel efficiency (mpg)", color = "Number of cylinder", caption = "Source: mtcars" ) + scale_color_unhcr_d() + theme_unhcr(legend_title = TRUE)
]
Show code alongside resulting plot, practical for teaching purpose.
Use the fig.show
and the ref.label
code chunk options to avoid repeating your code.
Chunk showing code: {r plot-name, fig.show = 'hide'}
Chunk showing plot: {r ref.label = 'plot-name', echo = FALSE}
The chunk showing the plot will NOT repeat the code but rather reference the code chunk by name.
.pull-left[
ggplot( mtcars, aes(x = hp, y = mpg, color = as.factor(cyl)) ) + geom_point(alpha = .8) + labs( title = "Simple scatterplot with ggplot", subtitle = "This plot shows the default style of theme_unhcr()", x = "Horsepower (hp)", y = "Fuel efficiency (mpg)", color = "Number of cylinder", caption = "Source: mtcars" ) + scale_color_unhcr_d() + theme_unhcr(legend_title = TRUE)
]
.pull-right[
]
.pull-left[ We recommend making sure your content fits the height of the slide, but sometimes output from R can be too big.
For this scenario, we include custom classes, to wrap the targeted content in the desired class:
.scroll-box-8[]
: show 8 lines.scroll-box-10[]
: show 10 lines.scroll-box-12[]
: show 12 lines.scroll-box-14[]
: show 14 lines.scroll-box-16[]
: show 16 lines.scroll-box-18[]
: show 18 lines.scroll-box-20[]
: show 20 lines]
.pull-right[
.scroll-box-12[]
example:
.scroll-box-12[
library(tidyverse) library(unhcrthemes) ggplot( mtcars, aes(x = hp, y = mpg, color = as.factor(cyl)) ) + geom_point(alpha = .8) + labs( title = "Simple scatterplot with ggplot", subtitle = "This plot shows the default style of theme_unhcr()", x = "Horsepower (hp)", y = "Fuel efficiency (mpg)", color = "Number of cylinder", caption = "Source: mtcars" ) + scale_color_unhcr_d() + theme_unhcr(legend_title = TRUE)
] ]
.footnote[ Thanks to Garth Tarr from the University of Sydney for the idea. ]
class: inverse, center, middle
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.