
MATH/COSC 3570 Introduction to Data Science
![]()


.qmd) to


![]()

knitr and Python/Julia uses Jupyter to evaluate our code and turn qmd into md file.


To generate a PDF report, you prefer writing this with 24 lines…


Or this with 250 lines!?



---
title: "ggplot2 demo"
date: "1/25/2025"
format: html
---
## Cars
There is a relationship between *miles per gallon* and *displacement*.
```{r}
mpg |> ggplot(aes(x = displ, y = hwy)) +
geom_point()
```Markdown Text
02-Quarto File
Go to your GitHub repo lab-yourusername. Clone it to your Posit Cloud as a project in 2025-Spring-Math-3570 workspace.
Open the file lab.qmd.
Change author in YAML.
Click on
or Ctrl/Cmd + Shift + K to produce a HTML document.
How can we show the current date every time we compile the file? [Hint:] Check your hw00. Compile your document and make sure the date shows up.
How do we fold the code so that the document is shorter? Describe it in ## Lab 2: Quarto
Once done, commit with message “02-quarto” and push it to GitHub.
| Markdown Syntax | Output |
|---|---|
|
italics and bold |
|
superscript2 / subscript2 |
|
|
|
verbatim code |
|
|
| Markdown Syntax | Output |
|---|---|
|
Header 1 |
|
Header 2 |
|
Header 3 |
|
Header 4 |
|
Header 5 |
|
Header 6 |
| Markdown Syntax | Output |
|---|---|
|
|
|
|
|
|
Markdown syntax
<https://www.google.com >
[Google link](https://www.google.com)
Output
inline-math: \(A = r^{2}\)
math-block: \[A = r^{2}\]
https://www.google.com
Google link
| Right | Left | Default | Center |
|------:|:-----|---------|:------:|
| 12 | 12 | 12 | 12 |
| 123 | 123 | 123 | 123 |
| 1 | 1 | 1 | 1 |
| Right | Left | Default | Center |
|---|---|---|---|
| 12 | 12 | 12 | 12 |
| 123 | 123 | 123 | 123 |
| 1 | 1 | 1 | 1 |
Source Mode

Visual Mode (What You See Is What You Mean (WYSIWYM))

knitr::kable() can turn dataframes into tables.
| mpg | cyl | disp | hp | drat | wt | qsec | vs | am | gear | carb | |
|---|---|---|---|---|---|---|---|---|---|---|---|
| Mazda RX4 | 21.0 | 6 | 160 | 110 | 3.90 | 2.62 | 16.5 | 0 | 1 | 4 | 4 |
| Mazda RX4 Wag | 21.0 | 6 | 160 | 110 | 3.90 | 2.88 | 17.0 | 0 | 1 | 4 | 4 |
| Datsun 710 | 22.8 | 4 | 108 | 93 | 3.85 | 2.32 | 18.6 | 1 | 1 | 4 | 1 |
| Hornet 4 Drive | 21.4 | 6 | 258 | 110 | 3.08 | 3.21 | 19.4 | 1 | 0 | 3 | 1 |
| Hornet Sportabout | 18.7 | 8 | 360 | 175 | 3.15 | 3.44 | 17.0 | 0 | 0 | 3 | 2 |
| Valiant | 18.1 | 6 | 225 | 105 | 2.76 | 3.46 | 20.2 | 1 | 0 | 3 | 1 |
03-Markdown
Back to your lab.qmd. In ## Lab 3: Markdown section, add a self-introduction paragraph containing a header, bold and italic text.
Add another paragraph that contains
Once done, commit with message “03-markdown” and push it to GitHub.
Has 3x backticks ``` on each end
To insert a code chunk,

Alt + Ctrl + I (Win) ; Option + Cmd + I (Mac)
Indicate engine (r) between curly braces {r}
Place options behind the #| (hashpipe): #| option: value
Tools > Modify Keyboard Shortcuts > Filter… > Insert Chunk Python > Option + Cmd + P (or any key binding you like)
echo
```r
```r
head(mtcars)
```
Which returns the below but is not executed since there aren’t {} around the language:
head(mtcars)echo: true where echo: false would instead hide the code but still evaluate it.1 + 1[1] 2
| Option | Run code | Show code | Output | Plots | Messages | Warnings |
|---|---|---|---|---|---|---|
eval: false |
x | x | x | x | x | |
include: false |
x | x | x | x | x | |
echo: false |
x | |||||
results: "hide" |
x | |||||
fig-show: "hide" |
x | |||||
message: false |
x | |||||
warning: false |
x |
execute key.Basic markdown syntax:

Maru
fig-, for example fig-width, fig-height, fig-show, etc.This is text with [special]{style="color:red"} formatting.
This is text with special formatting.
::: {style="color:red"}
This content can be styled with a border
:::
This content can be styled with a border
::: {#fig-maru layout-ncol=2}
{#fig-loaf width="250px"}
{#fig-lick width="250px"}
Two states of Maru
:::
Inside your text you can include code with the syntax `r your-r-code`.
For example, `r 4 + 5` would output 9 in your text.
Code in Quarto
There are `r num_cars` rows in the cars dataset. Four plus five is `r 4 + 5`
Output
There are 50 rows in the cars dataset. Four plus five is 9
04-Code Chunk
In lab.qmd ## Lab 4: Code Chunk, use code chunks to
include an image with knitr::include_graphics("URL or file path") https://raw.githubusercontent.com/rstudio/hex-stickers/master/PNG/ggplot2.png
include a plot plot(mtcars$disp, mtcars$mpg)
Show dataset mtcars as a table using knitr::kable()
Do some inline code calculation like `r ncol(mtcars)`, `r log(100, base = 10) + sqrt(4)`.
Add option fig-height: 4, fig-width: 6 and fig-align: right to the chunk for your plot. What are the changes?
How do we set global chunk options to not show the code in every chunk in the document?
Once done, commit with message “04-codechunk” and push your work to GitHub.