---
title: 'Lab 3: Basic Data Visualizations'
format:
  html:
    embed-resources: true
editor: source
knitr:
  opts_chunk:
    message: false
---

###### Question

::: question
Use the `library()` function to load the `tidyverse` package.
Then run `search()`, and confirm that you see `package:tidyverse` in the output. 
:::


![](https://freesvg.org/img/librarian_by_Juhele.png)

It's worth reflecting for a moment on the distinction between *installing* and *loading* a package. 
By way of analogy, consider the difference between buying a book and reading it. 

- Installing a package is like buying a book and putting it on your bookshelf. Once you have it, you don't need to buy another copy. So **you only have to install a package once**. You may eventually need to upgrade the book if a 2nd edition comes out, but once it's on your bookshelf, it's always available to you if you want it. However, the book is still *on your bookshelf* and not in your brain. Therefore, you can't actually use it. 
- Loading a package (via the `library()` function) is like taking the book off the shelf, placing it on your desk and opening it up. Now all of the information in that book is available to you. Once it's on your desk, it's available to you for as long as the book is on your desk. However, when you close your R session, all the books go back on the shelf! So **you have to `library()` a package each time you open a new R session**. 

At the same time, you don't want to `library()` more packages than you need, since then your desk will become cluttered. 


###### Question

::: question
Use the `library()` function to load the `palmerpenguins` package.
Then run `search()`, and confirm that you see `package:palmerpenguins` in the output. 
:::


###### Question

::: question
Modify the code snippet above to create a histogram for the `bill_length_mm` variable. 
:::



###### Question

::: question
Use the `geom_density()` function to modify the code snippet above to create a **density plot** for the `bill_length_mm` variable. 
:::



###### Question

::: question
Use the `geom_density()` function to create a **density plot** for the `bill_length_mm` variable, and use the `fill` aesthetic to separate the distributions by `island`. 
:::



###### Question

::: question
Use the `facet_wrap()` function to create a **density plot** for the `bill_length_mm` variable, separating the facets by `island`. 
:::


###### Question

::: question
You can add more than one `geom_*()` to a plot. There are lots of different `geom_*()` functions. Experiment with a couple of other options.
:::


###### Question

::: question
You can map additional aesthetics. `geom_point()` is perhaps the most versatile mark. In addition to `x`, `y`, `color`, and `fill`, it also understands `alpha`, `shape`, `size`, `stroke`, and `group`. Experiment by mapping a couple of these aesthetics to variables.
:::


###### Question

::: question
You can map the same variable to multiple aesthetics. For example, you can map `species` to **both** the `color` and `fill` aesthetic. Try this or another double mapping.
:::


###### Question

::: question
Use `ggplot2` to create a plot that looks like @fig-example. 
:::

 

```{r unnamed-chunk-16}
#| label: last-question
#| document: template
#| eval: false
ggplot(__??__) +
  geom_??()
```

