2025-05-05
First, load tidyverse and {palmerpenguin} packages
Go in the {r} header of code chunks (in one line)
label = chunk-label - chunk labeleval = TRUE - evaluates code chunkecho = TRUE - displays source code in documentinclude = TRUE - displays chunk output in documentmessage = TRUE - displays messages in documentwarning = TRUE - displays warnings in documenterror = TRUE - displays errors in documentGo in the {r} header of code chunks (in one line)
```{r chunk-label, echo = FALSE, message = FALSE, warning = FALSE}
```
Can also be separated from header using #| but must switch from = to :
```{r}
#| chunk-label
#| echo: FALSE
#| message: FALSE
#| warning: FALSE
```
Set options globally with knitr::opts_chunk$set()
```{r setup, include = FALSE}
knitr::opts_chunk$set(echo = FALSE, message = FALSE, warning = FALSE)
```
ggplot(penguins, aes(bill_length_mm, bill_depth_mm)) + geom_point()fig.width = 5, fig.height = 5
ggplot(penguins, aes(bill_length_mm, bill_depth_mm)) + geom_point()fig.width = 3, fig.height = 3
ggplot(penguins, aes(bill_length_mm, bill_depth_mm)) + geom_point()out.width = "30%", out.height = "30%"
ggplot(penguins, aes(bill_length_mm, bill_depth_mm)) + geom_point()
out.width = "300", out.height = "300"
ggplot(penguins, aes(bill_length_mm, bill_depth_mm)) + geom_point()
fig.align = "center"
ggplot(penguins, aes(bill_length_mm, bill_depth_mm)) + geom_point()fig.cap = "My figure caption"
ggplot(penguins, aes(bill_length_mm, bill_depth_mm)) + geom_point()Figure 1: My figure caption
fig.alt = "Scatterplot of penguin bill length by depth."
ggplot(penguins, aes(bill_length_mm, bill_depth_mm)) + geom_point()My figure caption
knitr::include_graphics("https://quarto.org/docs/authoring/images/crossref-figure.png")Make sure code chunk has a label and a caption
Use a bookdown output format (e.g., pdf_document2, word_document2, papaja::apa6_pdf, thesisdown)
Insert \@ref(fig:chunk-label) for figures and \@ref(tab:chunk-label) for tables (e.g., \@ref(fig:cap))
Note for Quarto, labels must start with @fig- or @tbl- and reference with @fig-label or @tbl-label (e.g., Figure 1 yields Figure 1)
Label sections with {#slug}
(e.g., ## Cross reference figures/tables {#sec-cross-reference})
Cross reference with \@ref(slug)
For Quarto, cross references must start with #sec- and are referenced with @sec-label (e.g., @sec-cross-reference yields Section 3.1)
bibliography to the project’s .bib file[@citation.key]: [@Stevens.etal.2023] yields (Stevens et al., 2023);: [@Stevens.etal.2022; @Stevens.etal.2023] yields (Stevens et al., 2022, 2023)[see @Stevens.etal.2023, pp. 25] yields (see Stevens et al., 2023, pp. 25)@Stevens.etal.2023 yields Stevens et al. (2023)-: [-@Stevens.etal.2023] yields (2023)---
nocite: |
@Stevens.etal.2023
...
csl to citation style .csl fileDocuments, manuscripts, books, theses, websites, presentations, dashboards, interactive apps
HTML, PDF, Word, ePub
R, Python, Julia, Observable