knitr::opts_chunk$set( collapse = TRUE, comment = "#>", warning = FALSE, message = FALSE, out.width = "100%" )
library(palmerpenguins) library(dplyr) library(ggplot2) theme_set(theme_minimal())
The palmerpenguins
R package contains two datasets that we believe are a viable alternative to Anderson's Iris data (see datasets::iris
). In this introductory vignette, we'll highlight some of the properties of these datasets that make them useful for statistics and data science education, as well as software documentation and testing.
You can download all the palmerpenguins art directly from
vignette("art")
The palmerpenguins
data contains size measurements for three penguin species observed on three islands in the Palmer Archipelago, Antarctica.
\ Aside: That's right, developers -- Gentoo Linux is named after penguins!
These data were collected from 2007 - 2009 by Dr. Kristen Gorman with the Palmer Station Long Term Ecological Research Program, part of the US Long Term Ecological Research Network. The data were imported directly from the Environmental Data Initiative (EDI) Data Portal, and are available for use by CC0 license ("No Rights Reserved") in accordance with the Palmer Station Data Policy.
You can install the released version of palmerpenguins from CRAN with:
install.packages("palmerpenguins")
Or install the development version from GitHub with:
# install.packages("remotes") remotes::install_github("allisonhorst/palmerpenguins")
This package contains two datasets:
Here, we'll focus on a curated subset of the raw data in the package named penguins
, which can serve as an out-of-the-box alternative to datasets::iris
.
The raw data, accessed from the Environmental Data Initiative (see full data citations below), is also available as palmerpenguins::penguins_raw
.
The curated palmerpenguins::penguins
dataset contains r ncol(penguins)
variables (n = r nrow(penguins)
penguins). You can read more about the variables by typing ?penguins
.
glimpse(penguins)
The palmerpenguins::penguins
data contains r sum(complete.cases(penguins))
complete cases, with r sum(is.na(penguins))
missing values.
visdat::vis_dat(penguins)
ggsave("vignettes/figs/penguin-visdat.png", width = 8)
knitr::include_graphics("figs/penguin-visdat.png")
We don't want to ruin all the fun exploration, visualization, and potential analyses, so below are just a few examples to get you quickly waddling along with penguins. You can check out more in vignette("examples")
.
The penguins
data has three factor variables:
penguins %>% dplyr::select(where(is.factor)) %>% glimpse()
# Count penguins for each species / island penguins %>% count(species, island, .drop = FALSE)
ggplot(penguins, aes(x = island, fill = species)) + geom_bar(alpha = 0.8) + scale_fill_manual(values = c("darkorange","purple","cyan4"), guide = FALSE) + theme_minimal() + facet_wrap(~species, ncol = 1) + coord_flip()
# Count penguins for each species / sex penguins %>% count(species, sex, .drop = FALSE)
ggplot(penguins, aes(x = sex, fill = species)) + geom_bar(alpha = 0.8) + scale_fill_manual(values = c("darkorange","purple","cyan4"), guide = FALSE) + theme_minimal() + facet_wrap(~species, ncol = 1) + coord_flip()
The penguins
data also has four continuous variables, making six unique scatterplots possible!
penguins %>% dplyr::select(body_mass_g, ends_with("_mm")) %>% glimpse()
# Scatterplot example 1: penguin flipper length versus body mass ggplot(data = penguins, aes(x = flipper_length_mm, y = body_mass_g)) + geom_point(aes(color = species, shape = species), size = 2) + scale_color_manual(values = c("darkorange","darkorchid","cyan4")) # Scatterplot example 2: penguin bill length versus bill depth ggplot(data = penguins, aes(x = bill_length_mm, y = bill_depth_mm)) + geom_point(aes(color = species, shape = species), size = 2) + scale_color_manual(values = c("darkorange","darkorchid","cyan4"))
You can add color and/or shape aesthetics in ggplot2
to layer in factor levels like we did above. With three factor variables to work with, you can add another factor layer with facets, like the plot below.
ggplot(penguins, aes(x = flipper_length_mm, y = body_mass_g)) + geom_point(aes(color = sex)) + scale_color_manual(values = c("darkorange","cyan4"), na.translate = FALSE) + facet_wrap(~species)
Also see vignette("pca")
for an example principal component analysis.
penguins %>% select(species, body_mass_g, ends_with("_mm")) %>% GGally::ggpairs(aes(color = species)) + scale_colour_manual(values = c("darkorange","purple","cyan4")) + scale_fill_manual(values = c("darkorange","purple","cyan4"))
ggsave("vignettes/figs/penguin-ggpairs.png", width = 8)
knitr::include_graphics("figs/penguin-ggpairs.png")
# Jitter plot example: bill length by species ggplot(data = penguins, aes(x = species, y = bill_length_mm)) + geom_jitter(aes(color = species), width = 0.1, alpha = 0.7, show.legend = FALSE) + scale_color_manual(values = c("darkorange","darkorchid","cyan4")) # Histogram example: flipper length by species ggplot(data = penguins, aes(x = flipper_length_mm)) + geom_histogram(aes(fill = species), alpha = 0.5, position = "identity") + scale_fill_manual(values = c("darkorange","darkorchid","cyan4"))
See more examples in:
vignette("examples")
, vignette("pca")
, and vignette("user_contributions")
Or contribute your own!
Please cite the palmerpenguins R package using:
citation("palmerpenguins")
Data originally published in:
Individual datasets:
Individual data can be accessed directly via the Environmental Data Initiative:
Palmer Station Antarctica LTER and K. Gorman, 2020. Structural size measurements and isotopic signatures of foraging among adult male and female Adélie penguins (Pygoscelis adeliae) nesting along the Palmer Archipelago near Palmer Station, 2007-2009 ver 5. Environmental Data Initiative. https://doi.org/10.6073/pasta/98b16d7d563f265cb52372c8ca99e60f (Accessed 2020-06-08).
Palmer Station Antarctica LTER and K. Gorman, 2020. Structural size measurements and isotopic signatures of foraging among adult male and female Gentoo penguin (Pygoscelis papua) nesting along the Palmer Archipelago near Palmer Station, 2007-2009 ver 5. Environmental Data Initiative. https://doi.org/10.6073/pasta/7fca67fb28d56ee2ffa3d9370ebda689 (Accessed 2020-06-08).
Palmer Station Antarctica LTER and K. Gorman, 2020. Structural size measurements and isotopic signatures of foraging among adult male and female Chinstrap penguin (Pygoscelis antarcticus) nesting along the Palmer Archipelago near Palmer Station, 2007-2009 ver 6. Environmental Data Initiative. https://doi.org/10.6073/pasta/c14dfcfada8ea13a17536e73eb6fbe9e (Accessed 2020-06-08).
Have fun with the Palmer Archipelago penguins!
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.