.qmd’s: RevisitedLast time (and what we’ve been using), we covered the building blocks of a .qmd:
Today, we’ll level up with tools that are especially useful when writing and styling reports:
Which renders as:
The HRS dataset has 2728 rows and 1468 households.
Inline code uses single backticks with a lowercase r right after the first backtick (no curly braces, unlike a chunk)
round():control decimal placescomma(): format big numbers with commas (in scales package)percent(): format proportions as % (in scales package)Code it in R and assign to objects:
Which renders as:
The mean income in the HRS dataset is $91,813 and the percent of responders who have trouble sleeping is 19.6%.
Quarto renders LaTeX math using MathJax — no extra setup needed
$...$$$...$$Which renders as:
The slope \(\beta_1\) describes the change in \(Y\) for a one-unit change in \(X\).
\[ Y_i = \beta_0 + \beta_1 X_i + \epsilon_i \]
We can use LaTeX math to write equations for the mean and proportion of a variable in our dataset
Which renders as:
\[ \overline{\text{income}} = \frac{1}{n}\sum_{i=1}^{n} \text{income}_i \]
\(\overline{\text{income}} = \text{\$}91,813\)
You can control how a chunk behaves with #| options at the top of the chunk:
| Option | What it does |
|---|---|
echo: false |
Hides the code in output (results still show) |
warning: false |
Hides warnings from the output |
include: false |
Hides both code and results (still runs) |
eval: false |
Don’t run the code (no output) |
qmd file has code that doesn’t work or takes a long time to run, but you still want to render the document
@fig-, tbl-, eq-, or sec-
If we want to create a table of summary statistics, we can use the label to reference it later in the text:
```{r}
#| label: tbl-summ-stats
#| fig-cap: "Summary statistics for income and trouble sleeping"
hrs_00 |>
select(income, sleep) |>
tbl_summary(
statistic = list(all_continuous() ~ "{mean} ({sd})")
)
```
In @tbl-summ-stats, we see the mean and standard deviation for income and
the proportion of respondents who report trouble sleeping.
| Characteristic | N = 2,7281 |
|---|---|
| Total Household Income | 91,813 (128,588) |
| Ever Had Sleep Disorder | 534 (20%) |
| 1 Mean (SD); n (%) | |
Summary statistics for income and trouble sleeping
In Table 1, we see the mean and standard deviation for income and the proportion of respondents who report trouble sleeping.
note, tip, warning, important, and cautiondefault, minimal, and simple
::: and {.callout-<type>} to create a callout block, then close it with ::: at the endWhich renders as:
This is a neutral, informational note.
::: {.panel-tabset} to create a tabset, then close it with ::: at the end
### Plot or ### Table) and the content for that tab goes below the header
Quarto and .qmd’s: Revisited