HDS 3.1-3.2

Author

Joseph Steinberg

library(tidyverse)
library(palmerpenguins)

Begin by loading the tidyverse and palmerpenguins packages in the code chunk above and adding your name as the author.

Visualizing the penguins Data

Categorical Variables

Let’s start by making a bar chart of the species variable. Modify this code by filling in the ______ to do so:

ggplot(data = penguins, mapping = aes(x = species)) +
  geom_bar() +
  labs(
    x = "Penguin Species",
    y = "Number of Penguins",
    title = "Distribution of Penguin Species near Palmer Station, Antarctica"
  )

Make a bar chart showing the number of penguins on each island by using the code above as a template:

ggplot(data = penguins, mapping = aes(x = island)) +
  geom_bar() +
  labs(
    x = "Island",
    y = "Number of Penguins",
    title = "Title Placeholder"
  )

Quantitative Variables

Now let’s make a histogram of the bill_length_mm variable. Modify this code by filling in the ______ to do so:

ggplot(penguins, mapping = aes(x = bill_length_mm)) +
  geom_histogram() +
  labs(
    x = "Penguins",
    y = "Bill Length (mm)",
    title = "Number of Penguins by Island"
  )

Make a histogram of flipper_length_mm and set the binwidth to 4. Use the code above as a template:

ggplot(penguins, mapping = aes(x = flipper_length_mm)) +
  geom_histogram(bindwith = 4) + 
  labs(
    x = "Penguins",
    y = "Flipper Length (mm)",
    title = "Flipper Length (mm) of Penguins"
  )
Warning in geom_histogram(bindwith = 4): Ignoring unknown parameters:
`bindwith`
`stat_bin()` using `bins = 30`. Pick better value `binwidth`.
Warning: Removed 2 rows containing non-finite outside the scale range
(`stat_bin()`).

Now make a density plot (instead of a histogram) of flipper_length_mm by using the geom_density() function:

ggplot(penguins, mapping = aes(x = flipper_length_mm)) +
  geom_density() + 
  labs(
    x = "Penguins",
    y = "Flipper Length (mm)",
    title = "Flipper Length (mm) of Penguins"
  )
Warning: Removed 2 rows containing non-finite outside the scale range
(`stat_density()`).

Suppose we would like to look at how flipper_length_mm differs across species. Modify this code by filling in the ______ to do so:

ggplot(penguins, mapping = aes(x = flipper_length_mm)) +
  geom_histogram() +
  facet_wrap( ~ species) +
  labs(
    x = "Flipper Length (mm)",
    y = "Species",
    title = "Penguin Flipper Length by Species"
  )

Do different species have distinctly different flipper lengths?

Yes, different species do have different flipper lengths on average.