Begin by loading the tidyverse and palmerpenguins packages in the code chunk above and adding your name as the author.
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr 1.1.4 ✔ readr 2.1.6
✔ forcats 1.0.1 ✔ stringr 1.6.0
✔ ggplot2 4.0.1 ✔ tibble 3.3.0
✔ lubridate 1.9.4 ✔ tidyr 1.3.2
✔ purrr 1.2.0
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag() masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
Attaching package: 'palmerpenguins'
The following objects are masked from 'package:datasets':
penguins, penguins_raw
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 = "Penguin Species" ,
y = "Number of Penguins" ,
title = "Distribution of Penguin Species 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 in Millimeters" ,
y = "Number of Penguins" ,
title = "Penguins by Bill Length"
)
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 () +
labs (
x = "Flipper Length in Millimeters" ,
y = "Number of Penguins" ,
title = "Penguins by Flipper Length"
) +
geom_histogram (binwidth = 4 )
`stat_bin()` using `bins = 30`. Pick better value `binwidth`.
Warning: Removed 2 rows containing non-finite outside the scale range (`stat_bin()`).
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 (data = penguins, mapping = aes (x = flipper_length_mm)) +
geom_density () +
labs (
x = "Flipper Length in Millimeters" ,
y = "Number of Penguins" ,
title = "Penguins by Flipper Length"
)
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 (data = penguins, mapping = aes (x = flipper_length_mm)) +
geom_histogram () +
facet_wrap ( ~ species) +
labs (
x = "Flipper Length in Millimeters" ,
y = "Species" ,
title = "Flipper Length Across Species"
)
Do different species have distinctly different flipper lengths?
Yes. It appears that, on average, Gentoo penguins have an average of about 220 millimeter flippers, while Chinstrap penguins are closer to 195 millimeters and Adelie are closer to 190 millimeters, according to our data plots.