Associated Material
Module: Module 05 - Communicate
Readings:
What is RMarkdown
There are three main components to an RMarkdown document
- The YAML header which is surrounded by
---
s and provides information for the compiling
process
- R code chunks which are surrounded by
```
s
- Text which can be formatted using the Markdown language.
A reference guide of RMarkdown syntax can be found through
Help
-> Cheat Sheets
->
R Markdown Reference Guide
in the RStudio menu.
Example Rmd
Create your own RMarkdown document now from the template. To do this
go File
-> New File
->
R Markdown
.
Knitting
“Knit” or compile the document using the knit
button or
Ctrl + Shift + K.
Code Chunks
Code chunks look like:
```{r}
1 + 2
```
Code chunks are executed as part of the document “knitting” and
the code and output embedded in the document
Be aware of the working directory (don’t use
setwd()
). Ideally use the here
package to
manage paths.
Exercises
- Create a new RMarkdown file called with the output being HTML.
- fill in your name and the title
My Report
- Save the file as
my_report.Rmd
and knit it.
- Modify the
setup
code chunk to load the
tidyverse
package
- Remove the template content starting on the line with
## R Markdown
and below.
- Create a code chunk to read in the gapminder data used in Module 2 - Visualising
- Watch out for your file paths relative to your Rmd file
- Choose two countries and filter the data to only include them
- Make a plot of life expectancy versus gdp per capita
- In the text areas of the RMarkdown note some observations about your
plot. Include:
- a level 2 heading
- something in italics
- something in bold
- Underneath your plot include a table of the data for your
countries
LS0tCnRpdGxlOiAiWm9vbSBOb3RlcyAwNTogQ29tbXVuaWNhdGluZyBEYXRhIgpkYXRlOiAiU2VtZXN0ZXIgMiwgMjAyMyIKb3V0cHV0OgogIGh0bWxfZG9jdW1lbnQ6CiAgICB0b2M6IHRydWUKICAgIHRvY19mbG9hdDogdHJ1ZQogICAgdG9jX2RlcHRoOiAzCiAgICBjb2RlX2Rvd25sb2FkOiB0cnVlCiAgICBjb2RlX2ZvbGRpbmc6IHNob3cKLS0tCgpgYGB7ciBzZXR1cCwgaW5jbHVkZT1GQUxTRX0KbGlicmFyeShrbml0cikKCmtuaXRyOjpvcHRzX2NodW5rJHNldCgKICBjb21tZW50ID0gIiM+IiwKICBmaWcucGF0aCA9ICJmaWd1cmVzLzA1LyIsICMgdXN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