Week 12 Exercises: Quarto document

Author
Affiliation

Jelmer Poelstra

Published

November 10, 2025



1 Setting up

2 Exercise

2.1 YAML header

  1. Save your Quarto (.qmd) file that contains your script in HTML format.

  2. Add the following key–value pairs to the YAML header of your Quarto document:

  • Author name
  • Date
  • Table of contents
  1. Create nested format options in the YAML header using format: html: and set the theme to cyborg.

2.2 Code Chunks

  1. Install the palmerpenguins package in the Console, and load the package in a code chunk of your Quarto document. Save the penguins dataset in an object called penguin_data.

  2. Open the second code chunk, select the columns flipper_length_mm, island , year and save them as new_penguins object. Add a code chunk option to hide the code in the rendered file.

  3. Use penguin_data to create a scatter plot with the ggplot2 package of tidyverse. Set flipper_length_mm as the x-axis and body_mass_g as the y-axis. Refer to the ggplot2 documentation to understand the syntax of scatter plot. We will discuss ggplot in Week 13.

  4. Customize your figure by:

  • Adding a figure caption
  • Changing the figure dimensions (height and width)
  • Aligning the figure to the center using chunk options
  1. Render your document, download the output, and verify that it includes the scatter plot.

  2. If document does not contain scatter plot, add the appropriate option in the YAML header to include figures in the HTML output.

  3. Render the document again and confirm that the scatter plot is now included.

2.3 Text

  1. Add headers of different levels above your code chunks.

  2. Write a short text section describing the scatter plot you created in question 9.

3 Solutions

3.1 YAML header

1-3. YAML header
##The solution of these questions are provided in the exercise of week12 lecture.

3.2 Code chunks

4. install palmerpenguins package and save object
library(palmerpenguins)

Attaching package: 'palmerpenguins'
The following objects are masked from 'package:datasets':

    penguins, penguins_raw
penguin_data <- penguins
5. Select columns
## First load tidyverse to use select function
library(tidyverse)
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr     1.1.4     ✔ readr     2.1.5
✔ forcats   1.0.0     ✔ stringr   1.5.2
✔ ggplot2   3.5.2     ✔ tibble    3.3.0
✔ lubridate 1.9.4     ✔ tidyr     1.3.1
✔ purrr     1.1.0     
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag()    masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
new_penguins <- penguin_data |> 
  select( flipper_length_mm, island , year)
6. Scatter plot
library(ggplot2)
penguin_data |> 
  ggplot(aes(flipper_length_mm, body_mass_g)) +
  geom_point()
Warning: Removed 2 rows containing missing values or values outside the scale range
(`geom_point()`).

7. Customize your plot
```{r}
#| fig-cap: "Scatter plot of palmerpenguins datasets"
#| fig-width: 5
#| fig-height: 4
#| fig-align: center
penguin_data |> 
  ggplot(aes(flipper_length_mm, body_mass_g)) +
  geom_point()
```
Warning: Removed 2 rows containing missing values or values outside the scale range
(`geom_point()`).

Scatter plot of palmerpenguins datasets
8. Include your plot in HTML

embed-resources: true in your YAML header to make your document self-contained

Back to top