Quarto demonstration

Julia Müller

1/18/23

Preparation

Choosing the data

As everyone always says,

penguins are very cute!

…so let’s work with penguin data today.

Note

Note that the palmerpenguins dataset is meant as an alternative to the commonly used iris data.

More information on this data set is available on Allison Horst’s Github page.

This data can also be used via the {palmerpenguins} package (Horst et al., 2020) and was originally introduced in Gorman et al. (2014)

Loading packages & reading data

First, we need to:

  1. load packages
  2. read in data
  3. check if that data is in the right format

Using the data without downloading it

This same dataset is also available in the package palmerpenguins.

library(tidyverse)
penguins <- read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2020/2020-07-28/penguins.csv') %>% 
  drop_na()
head(penguins)
# A tibble: 6 × 8
  species island    bill_length_mm bill_depth_mm flipper_l…¹ body_…² sex    year
  <chr>   <chr>              <dbl>         <dbl>       <dbl>   <dbl> <chr> <dbl>
1 Adelie  Torgersen           39.1          18.7         181    3750 male   2007
2 Adelie  Torgersen           39.5          17.4         186    3800 fema…  2007
3 Adelie  Torgersen           40.3          18           195    3250 fema…  2007
4 Adelie  Torgersen           36.7          19.3         193    3450 fema…  2007
5 Adelie  Torgersen           39.3          20.6         190    3650 male   2007
6 Adelie  Torgersen           38.9          17.8         181    3625 fema…  2007
# … with abbreviated variable names ¹​flipper_length_mm, ²​body_mass_g

We’ve removed missing values here, which means that the data has 333 rows now1.

Some descriptive statistics

Figure 1: Penguin species drawing by Allison Horst

Figure 2: Explaining bill dimensions

The average bill length is 43.9927928 mm and the average bill depth is 17.1648649 mm.

The data was collected between 2007 and 2009.

Comparing base R and tidyverse syntax

Here’s code to see data in a specific column:

penguins$bill_length_mm
penguins %>% select(bill_length_mm)

Graphs

Some ideas for graphs:

  • penguin weight by flipper length
    • for the entire data
    • or separately for each species
    • and additionally by sex
  • flipper and bill length
  • bill length and depth

Weight and flipper length

The following graphs are slightly simplified versions from the vignette for the {palmerpenguins} package.

Entire data

mass_flipper <- ggplot(data = penguins,
                       aes(x = flipper_length_mm,
                           y = body_mass_g)) +
  geom_point(size = 3,
             alpha = 0.8) +
  theme_minimal() +
  labs(title = "Penguin size, Palmer Station LTER",
       subtitle = "Flipper length and body mass for Adelie, Chinstrap and Gentoo Penguins",
       x = "Flipper length (mm)",
       y = "Body mass (g)") +
  theme_minimal()

Figure 3: Penguin flipper length and body mass

Refer to Figure 2 for an explanation of the measurements.

Separated by species

mass_flipper_species <- ggplot(data = penguins,
                       aes(x = flipper_length_mm,
                           y = body_mass_g)) +
  geom_point(aes(color = species,
                 shape = species),
             size = 3,
             alpha = 0.8) +
  theme_minimal() +
  scale_color_manual(values = c("darkorange","purple","cyan4")) +
  labs(title = "Penguin size, Palmer Station LTER",
       subtitle = "Flipper length and body mass for Adelie, Chinstrap and Gentoo Penguins",
       x = "Flipper length (mm)",
       y = "Body mass (g)",
       color = "Penguin species",
       shape = "Penguin species") +
  theme_minimal()

Figure 4: Penguin flipper length and body mass, separately by species

Figure 3 does not separate the data by species, while Figure 4 does.

Separated by species and sex

mass_flipper_species_sex <- 
  mass_flipper_species +
  facet_wrap(~sex)

Figure 5: Penguin flipper length and body mass, separately by species and sex

References

Gorman, K. B., Williams, T. D., & Fraser, W. R. (2014). Ecological sexual dimorphism and environmental variability within a community of antarctic penguins (genus pygoscelis). PloS One, 9(3), e90081. https://doi.org/10.1371/journal.pone.0090081
Horst, A. M., Presmanes Hill, A., & Gorman, K. B. (2020). Palmerpenguins: Palmer archipelago (antarctica) penguin data. R package version 0.1.0. Zenodo. https://doi.org/10.5281/zenodo.3960218