```{r}
1.8 Formatting with Quarto
In this assignment, you will recreate a Quarto document that I’ve already compiled (workbook appendix). You can only see the compiled HTML version, and your task is to reverse-engineer the quarto file by adding the necessary formatting, text, math, and code chunks in your own document. This exercise will help you become familiar with using Quarto, which you’ll need throughout the course.
Getting Started:
Go here: https://cran.r-project.org/ and follow the instructions to download R for your Linux, Windows, or Mac. You should download the latest release.
Then go here: https://posit.co/download/rstudio-desktop/ and click the blue button that says step 2: install RStudio Desktop.
Mac users: make sure you know whether you have an Apple silicon mac or an older intel-based mac and make sure that you download the correct version of R. If you’re using a mac, you’ll also need to install xquartz: https://www.xquartz.org/.
Open Rstudio and go to
File > New File > Quarto Document
.Add a title to the file and enter you and your groupmates’ names under Author.
Keep the format at HTML and hit Create.
Avoid the visual editor at all costs: make sure to toggle over to source and leave it there.
You’ll also want to periodically save your document (
Command S
on Mac,Ctrl S
on Windows) and compile it to HTML (hitRender
) to see your progress.Install the tidyverse: in your RStudio console, run the line of code
install.packages("tidyverse")
Quarto Formatting Hints:
Text is formatted using markdown:
- Use
*text*
or_text_
for italics. - Use
**text**
or__text__
for bold. - Use
#
for headings. The number of#
symbols determines the heading level:#
for Heading 1##
for Heading 2###
for Heading 3
- Lists:
- For bullet points, use
-
or*
. - For numbered lists, use
1.
,2.
,3.
, etc.
- For bullet points, use
- Tables:
- Use pipes
|
to separate columns and hyphens-
to create headers. For example:
- Use pipes
| This | is | a | table |
|------|------|-------|-------|
| with | some | words | in |
| it. | | | |
Math is formatted using LaTeX:
- Math Mode
- Use
$...$
for inline math. - Use
$$...$$
for display math (centered and in its own line).
- Use
- Subscripts and superscripts
- Use
_
for subscripts, e.g.,x_i
. - Use
^
for superscripts, e.g.,x^2
.
- Use
- Fractions
- Use
\frac{numerator}{denominator}
.
- Use
- Special symbols:
- Use
\sim
for tilde,\partial
for partial derivatives,\ln
for natural logarithm.
- Use
- Text inside math mode:
- Use
\text{Words Here}
.
- Use
- Aligning Equations:
- Use the
align
environment to align equations. When you’re using the align environment, you don’t need to add any dollar signs to enter math mode. For example, use\begin{align}
,\end{align}
, and&
to say where you want equations to align. The\\
indicates a line ending:
- Use the
\begin{align}
y &= mx + b \\
z &= x^2 + y^2
\end{align}
Here’s how to add R code, especially to draw a plot:
- Initialize an R Code Chunk:
- close it in another line with another three tics:
```
- The first line of your code chunk should be:
library(tidyverse)
. This command loads the tidyverse package into the session of the quarto document, which includes ggplot2, the package you’ll use to create the plot. - Then create a blank plot with the ggplot() function:
ggplot()
- Use the
+
operator to add layers to your plot. For example, to add a line representing the function \(f(x) = 3x + 2\), use:
ggplot() +
stat_function(fun = function(x) 3 * x + 2, color = "red")
- Note that in R, multiplication uses the asterisk:
*
, addition uses+
, subtraction uses-
, division uses/
, exponentiation uses^
, and parentheses can be used for grouping expressions:
3 / 2) * 2 ^ 2 (
[1] 6