HDS 3.1-3.2

Author

Gabriel Issa

library(tidyverse)
library(datasets)

We will begin by loading the tidyverse and datasets 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:

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"
  )

Next, we made 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 = "Penguin Species",
    y = "Number of Penguins",
    title = "Distribution of Penguins per Island near Palmer Station, Antarctica"
  )

Quantitative Variables

Now let’s make a histogram of the bill_length_mm variable:

ggplot(data=penguins, mapping = aes(x = bill_len)) +
  geom_histogram() +
  labs(
    x = "Size",
    y = "Penguins",
    title = "Distribution of Penguin Bill length"
  )

Than, we made a histogram of flipper_length_mm and set the binwidth to 4 using the code above as a template:

ggplot(data=penguins, mapping = aes(x = flipper_len)) +
  geom_histogram(binwidth = 4) +
  labs(
    x = "Size",
    y = "Penguins",
    title = "Distribution of Penguin Flipper Length"
  )

Now let’s 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_len)) +
  geom_density(binwidth = 4) +
  labs(
    x = "Size",
    y = "Penguins",
    title = "Distribution of Penguin Flipper Length"
  )

Suppose we would like to look at how flipper_length_mm differs across species:

ggplot(data=penguins, mapping = aes(x = flipper_len)) +
  geom_histogram() +
  facet_wrap( ~ species) +
  labs(
    x = "Flipper Length",
    y = "Number of Penguins",
    title = "Flipper length per Species"
  )

Do different species have distinctly different flipper lengths?

By looking above, I think they do!