HDS 3.1-3.2

Author

Cheyanne Bunnell

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 = "Islands",
    y = "Number of Penguins",
    title = "Distribution of Penguins near Palmer Station, Antarctica"
  )

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(data = penguins, mapping = aes(x = bill_length_mm)) +
  geom_histogram() +
  labs(
    x = "Bill Length (mm)",
    y = "Number of Penguins",
    title = "Distribution of Penguins Bill Length near Palmer Station, Antarctica"
  )

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

ggplot(data = penguins, mapping = aes(x = flipper_length_mm)) +
  geom_histogram(binwidth = 4) +
  labs(
    x = "Flipper Length (mm)",
    y = "Number of Penguins",
    title = "Distribution of Penguins Flipper Length near Palmer Station, Antarctica"
  )

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

ggplot(data = penguins, mapping = aes(x = flipper_length_mm)) +
  geom_density() +
  labs(
    x = "Flipper Length (mm)",
    y = "Percent of Total Penguins",
    title = "Flipper Length near Palmer Station, Antarctica"
  )

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(data = penguins, mapping = aes(x = flipper_length_mm)) +
  geom_histogram() +
  facet_wrap( ~ species) +
  labs(
    x = "Flipper Length (mm)",
    y = "Number of Penguins",
    title = "Distribution of Flipper Length across Penguin Species"
  )

Do different species have distinctly different flipper lengths?

Adelie, look to have, on average, shorter flipper length under 210mm. Chinstrap, look to have between 180 and 210mm. Gentoo, seem to have the longest flipper length all above 200mm. There might be evidence that Adelie and Gentoo have distinctly different flipper length, otherwise there does not look to be any distinct difference.