| continent | mean_life_exp | mean_gdp |
|---|---|---|
| Africa | 54.80604 | 3089.033 |
| Americas | 73.60812 | 11003.032 |
| Asia | 70.72848 | 12473.027 |
| Europe | 77.64860 | 25054.482 |
| Oceania | 80.71950 | 29810.188 |
Day 3 - Introduction to Data Analysis with R
Freie Universität Berlin - Theoretical Ecology
October 17, 2026
So far, you’ve been writing .R scripts.
This is great for running code, but what if you want to
If you have to repeat the analysis
Quarto lets you combine code, text, and output in one document.
Advantages:
Quarto is an open-source scientific and technical publishing system
Today we focus on documents.
More info online: Get started with Quarto in RStudio
File -> New File -> Quarto Document...
Ctrl + Shift + KRStudio will run all the code, combine it with your text, and produce the output document.
.qmd documentA .qmd file has three types of content:
More online: Markdown basics
Markdown is a simple markup language to create formatted text.
The basics
**text** becomes text*text* becomes textLists
Links
[Quarto website](https://quarto.org) becomes Quarto website
You don’t need to memorize all of this. Here is a quick reference.
More online: Using R in Quarto
Code chunks start and end with 3 backticks and contain R code:
```{r}
library(tidyverse)
library(gapminder)
ggplot(gapminder, aes(x = gdpPercap, y = lifeExp)) +
geom_point()
```Insert a code chunk
Code -> Insert chunkCtrl + Alt + I / Cmd + Option + IRun a code chunk
Code chunks have special comments starting with #| that control the output:
```{r}
#| echo: false
#| warning: false
ggplot(gapminder, aes(x = gdpPercap, y = lifeExp)) +
geom_point()
```echo: Show the code in the output?eval: Run the code?include: Show code and output? (the code still runs)warning: Show warnings?message: Show messages?All options take true or false.
You can also include R code inside text using inline code:
becomes:
The gapminder data contains 1704 observations.
This means numbers update automatically when the data changes.
More online: HTML document options
The YAML header is at the top of the document between --- markers:
This sets the title, author, date, output format, and editor.
You can set default options for all code chunks:
---
title: "My analysis"
author: "Selina Baldauf"
format: html
execute:
warning: false
message: false
---These can be overwritten by individual chunk options.
Task (30 min)
Reproducible documents with Quarto
Find the task description here
Change the output format in the YAML header:
You might need to install LaTeX first. The most convenient is to use the tinytex package:
Add options to the YAML header to customize your document:
toc: Add a table of contentsnumber-sections: Number the section headerscode-fold: Hide code behind a button (HTML only)Control how figures appear in the output:
```{r}
#| label: fig-life-exp
#| fig-cap: "Life expectancy vs. GDP per capita in 2007"
#| fig-align: center
#| out-width: "80%"
ggplot(gapminder, aes(x = gdpPercap, y = lifeExp)) +
geom_point(aes(color = continent)) +
theme_minimal()
```fig-cap: Figure captionfig-align: left, center, or rightout-width: Width of the figure in the outputlabel: Must start with fig- for figuresYou can reference labeled figures in the text:
becomes:
As we can see in Figure 1, life expectancy increases with GDP.
kable()By default, tibbles print as plain text. Use knitr::kable() to render a nice table:
```{r}
gapminder |>
filter(year == 2007) |>
group_by(continent) |>
summarize(
mean_life_exp = mean(lifeExp),
mean_gdp = mean(gdpPercap)
) |>
knitr::kable()
```| continent | mean_life_exp | mean_gdp |
|---|---|---|
| Africa | 54.80604 | 3089.033 |
| Americas | 73.60812 | 11003.032 |
| Asia | 70.72848 | 12473.027 |
| Europe | 77.64860 | 25054.482 |
| Oceania | 80.71950 | 29810.188 |
Quarto can do much more:
Check out the Quarto website for guides, examples, and a gallery.
Selina Baldauf // Reproducible documents with Quarto