Let’s take a look at some data using the {palmerpenguins} R package by Allison Horst. First, load up the package itself.
# Install the {palmerpenguins} package if you need to:
# install.packages("palmerpenguins")
library(palmerpenguins)
Now check the first few rows of the penguins data set that is included in the {palmerpenguins} package.
head(penguins)
## # A tibble: 6 x 8
## species island bill_length_mm bill_depth_mm flipper_length_~ body_mass_g sex
## <fct> <fct> <dbl> <dbl> <int> <int> <fct>
## 1 Adelie Torge~ 39.1 18.7 181 3750 male
## 2 Adelie Torge~ 39.5 17.4 186 3800 fema~
## 3 Adelie Torge~ 40.3 18 195 3250 fema~
## 4 Adelie Torge~ NA NA NA NA <NA>
## 5 Adelie Torge~ 36.7 19.3 193 3450 fema~
## 6 Adelie Torge~ 39.3 20.6 190 3650 male
## # ... with 1 more variable: year <int>
Finish with a plot of penguin body mass by species!
# Install the {ggplot2} package if you need to:
# install.packages("ggplot2)
# Load ggplot2 for plotting
library(ggplot2)
# Make a plot using the penguins data
p <- ggplot(
data = penguins,
aes(x = body_mass_g, y = species, colour = species))
p <- p + geom_boxplot(width = 0.5, size = 1)
p <- p + geom_jitter(height = 0.2, alpha = 0.5, size = 3)
# Display the plot
p
## Warning: Removed 2 rows containing non-finite values (stat_boxplot).
## Warning: Removed 2 rows containing missing values (geom_point).