2023-05-08
First, load tidyverse and {palmerpenguin} packages
Go in the {r} header of code chunks (in one line)
label = my-chunk - 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 my-chunk, echo = FALSE, message = FALSE, warning = FALSE}
```
Can also be separated from header using #|
```{r}
#| my-chunk, 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()
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., bookdown::pdf_document2, papaja::apa6_pdf, thesisdown)
Insert \ref{fig:chunk-label} for figures and \ref{tab:chunk-label} for tables
Note for Quarto, labels must start with fig- or tbl- and reference with @fig-label or @tbl-label (e.g., 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., Section 4.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: |
@Barela.etal.2023
...
remotes::install_github("crsh/citr")
csl to citation style .csl file