---
title: "Literate Programming and Interactive Notebooks"
format: html # html, pdf, docx, revealjs, pptx
editor: visual
execute:
  warning: false
  message: false
  echo: true
---

```{r}
library(palmerpenguins)
library(dplyr)
library(ggplot2)
library(gt)
```

## Meet Quarto

Quarto enables you to write together text and executable code into a single file.

When you click the **Render** button a document will be generated that includes the text, the code and the output.

## Meet the penguins

For this exercise, we will use the penguins database from the `palmerpenguins` package.

See here: <https://github.com/allisonhorst/palmerpenguins>

Package DOI: 10.5281/zenodo.3960218

Paper DOI: 10.1371/journal.pone.0090081

This database contains measurements for three penguin species from the Palmer Archipelago in Antarctica.

![The Palmer Archipelago penguins. Artwork by @allison_horst.](figures/lter_penguins.png){fig-align="center" width="60%"}

These data were collected from 2007 - 2009 by Dr. Kristen Gorman with the [Palmer Station Long Term Ecological Research Program](https://pal.lternet.edu/), part of the [US Long Term Ecological Research Network](https://lternet.edu/).

```{r}
glimpse(penguins)
```

![Penguin bill dimensions. Artwork by Artwork by @allison_horst.](figures/bill_dimensions.png){fig-alt="The Palmer Archipelago penguins. Artwork by @allison_horst." fig-align="center" width="60%"}

## Figures

### Figure X. Penguin bill dimensions

```{r}
#| label: fig-penguins_01
#| fig-cap: Bill length versus bill depth across penguin species.

ggplot(data = penguins, aes(x = bill_length_mm, y = bill_depth_mm)) +
  geom_point(aes(color = species, shape = species), size = 2)  +
  scale_color_manual(values = c("darkorange","darkorchid","cyan4")) +
  theme_minimal() +
  labs(
    title = "Penguin Bill Dimensions",
    x = "Bill Length (mm)",
    y = "Bill Depth (mm)"
  )

```

## Tables

### Table Y. Penguin bill dimensions

The table below shows the average values of bill length (mm) and bill depth (mm) per species in each island.

```{r}
#| label: tbl-penguins-bill-dimensions
#| tbl-cap: Mean bill length (mm) and bill depth (mm) per species in each island.

penguins |>
  group_by(species, island) |>
  summarise(
    avg_bill_length = mean(bill_length_mm, na.rm = TRUE),
    avg_bill_depth  = mean(bill_depth_mm, na.rm = TRUE),
    .groups         = "drop"
  ) |>
  gt()
```

## Package citation

Please cite the `palmerpenguins` R package using:

```{r}
citation("palmerpenguins")
```
