Quarto Quick Reference Guide

Quarto is the next-generation version of R Markdown that combines code, results, and narrative text into dynamic documents. This guide covers the essentials you’ll need for STA 312.

Document Structure

Every Quarto document starts with a YAML header (between --- lines) that contains metadata:

---
title: "My Statistical Analysis"
author: "Your Name"
date: today
format: html
execute:
  echo: true
  warning: false
---

Basic Markdown Syntax

Headers

# Header 1 (largest)
## Header 2
### Header 3
#### Header 4

Text Formatting

  • Bold text: **bold text** or __bold text__
  • Italic text: *italic text* or _italic text_
  • Code text: `code text`
  • Links: [link text](URL)

Lists

Unordered lists:

- Item 1
- Item 2
  - Sub-item
  - Sub-item

Ordered lists:

1. First item
2. Second item
3. Third item

R Code Chunks

The power of Quarto comes from embedding R code directly in your document.

Basic Code Chunk

Code chucks start with {r}.

```{r}
# Your R code here
x <- c(1, 2, 3, 4, 5)
mean(x)
```

Code Chunk Options

Your code chunks can have options that are written in YAML style starting with a #| at the beginning of the line.

```{r}
#| label: data-setup
#| echo: false
#| message: false
#| warning: false

# Load libraries and data
library(tidyverse)
library(ggplot2)
```

Common Chunk Options

  • #| echo: false: Hide code, show output
  • #| eval: false: Show code, don’t run it
  • #| include: false: Run code, hide everything
  • #| message: false: Hide messages
  • #| warning: false: Hide warnings
  • #| fig-width: 8 and #| fig-height: 6: Control plot dimensions

Inline R Code

You can include R results directly in text using `r`:

The mean of our data is `r round(mean(x), 2)`.

Mathematical Expressions

Quarto uses LaTeX syntax for mathematical notation:

Inline Math

Use single dollar signs for inline math: $x^2 + y^2 = z^2$

Display Math

Use double dollar signs for centered display math:

$$\bar{x} = \frac{1}{n}\sum_{i=1}^{n} x_i$$

Common Statistical Notation

Concept LaTeX Code Rendered Output
Mean $\bar{x}$ \(\bar{x}\)
Standard deviation $\sigma$ \(\sigma\)
Regression equation $y = \beta_0 + \beta_1 x + \epsilon$ \(y = \beta_0 + \beta_1 x + \epsilon\)
Sums $\sum_{i=1}^{n} x_i$ \(\sum_{i=1}^{n} x_i\)
Square root $\sqrt{n}$ \(\sqrt{n}\)
Fractions $\frac{a}{b}$ \(\frac{a}{b}\)
Subscripts $x_i$ \(x_i\)
Superscripts $x^2$ \(x^2\)
Matrices $\begin{bmatrix} 1 & 2 & 3 \\ 4 & 5 & 6 \end{bmatrix}$ \(\begin{bmatrix} 1 & 2 & 3 \\ 4 & 5 & 6 \end{bmatrix}\)

Tables

Simple Tables

| Variable | Mean | SD   |
|----------|------|------|
| Height   | 68.2 | 3.1  |
| Weight   | 155  | 22.5 |

Tables from R Code

```{r}
#| label: summary-table
#| tbl-cap: "Summary Statistics"

library(knitr)
summary_stats <- data.frame(
  Variable = c("Height", "Weight"),
  Mean = c(68.2, 155.0),
  SD = c(3.1, 22.5)
)
kable(summary_stats)
```

Figures

Plots with Captions

```{r}
#| label: fig-scatter
#| fig-cap: "Relationship between height and weight"
#| fig-width: 6
#| fig-height: 4

ggplot(data, aes(x = height, y = weight)) +
  geom_point() +
  geom_smooth(method = "lm") +
  labs(x = "Height (inches)", y = "Weight (lbs)")
```

Cross-References

You can reference figures, tables, and equations:

  • Reference a figure: @fig-scatter
  • Reference a table: @tbl-summary
  • Reference an equation: @eq-regression

For equations with labels:

$$y = \beta_0 + \beta_1 x + \epsilon$$ {#eq-regression}

Callout Blocks

Quarto provides special callout blocks for important information:

::: {.callout-note}
This is a note callout.
:::

::: {.callout-warning}
This is a warning callout.
:::

::: {.callout-important}
This is an important callout.
:::

Rendering Your Document

To render your Quarto document:

  • In RStudio: Click the “Render” button
  • Command line: Run quarto render filename.qmd
  • Preview: Use quarto preview filename.qmd for live preview

Tips for Statistical Writing

  1. Always explain your code: Use comments (#) and narrative text
  2. Round numbers appropriately: Use round() function for inline code
  3. Label your chunks: Makes debugging easier
  4. Include figure captions: Helps with interpretation