Import Data

penguins <- read_csv("penguins.csv")
## Rows: 344 Columns: 8
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (3): species, island, sex
## dbl (5): bill_length_mm, bill_depth_mm, flipper_length_mm, body_mass_g, year
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.

Introduction

Questions

Variation

ggplot(data = penguins) +
    geom_bar (mapping = aes (x = island))

ggplot(data = penguins) +
    geom_histogram(mapping = aes (x = bill_length_mm), binwidth = 0.5)
## Warning: Removed 2 rows containing non-finite outside the scale range
## (`stat_bin()`).

Visualizing distributions

ggplot (data = penguins) +
    geom_bar(mapping = aes (x = species))

penguins %>% count(species)
## # A tibble: 3 × 2
##   species       n
##   <chr>     <int>
## 1 Adelie      152
## 2 Chinstrap    68
## 3 Gentoo      124
ggplot(data = penguins) +
    geom_histogram(mapping = aes (x = bill_depth_mm))
## `stat_bin()` using `bins = 30`. Pick better value `binwidth`.
## Warning: Removed 2 rows containing non-finite outside the scale range
## (`stat_bin()`).

ggplot (data = penguins, mapping = aes(x = bill_length_mm, colour = species)) +
    geom_freqpoly(binwidth = 0.1)
## Warning: Removed 2 rows containing non-finite outside the scale range
## (`stat_bin()`).

Typical values

Unusual values

Missing Values

Covariation

ggplot(data = penguins, mapping = aes(x = bill_depth_mm)) + 
  geom_freqpoly(mapping = aes(colour = species), binwidth = 500)
## Warning: Removed 2 rows containing non-finite outside the scale range
## (`stat_bin()`).

ggplot(penguins) + 
  geom_bar(mapping = aes(x = bill_depth_mm))
## Warning: Removed 2 rows containing non-finite outside the scale range
## (`stat_count()`).

ggplot(data = penguins, mapping = aes(x = island, y = body_mass_g)) +
  geom_boxplot()
## Warning: Removed 2 rows containing non-finite outside the scale range
## (`stat_boxplot()`).

A categorical and continuous variable

ggplot(data = penguins, mapping = aes(x = body_mass_g)) + 
  geom_freqpoly(mapping = aes(colour = island), binwidth = 500)
## Warning: Removed 2 rows containing non-finite outside the scale range
## (`stat_bin()`).

ggplot(penguins) + 
  geom_bar(mapping = aes(x = island))

Two categorical variables

ggplot(data = penguins) +
  geom_count(mapping = aes(x = species, y = island))

penguins %>% 
  count(species, island) %>%  
  ggplot(mapping = aes(x = species, y = island)) +
    geom_tile(mapping = aes(fill = n))

ggplot(data = penguins) +
  geom_bin2d(mapping = aes(x = species, y = island))
## `stat_bin2d()` using `bins = 30`. Pick better value `binwidth`.

# install.packages("hexbin")
ggplot(data = penguins) +
  geom_hex(mapping = aes(x = species, y = island))

Two continous variables

ggplot(data = penguins) +
  geom_point(mapping = aes(x = sex, y = bill_depth_mm))
## Warning: Removed 2 rows containing missing values or values outside the scale range
## (`geom_point()`).

ggplot(data = penguins) + 
  geom_point(mapping = aes(x = sex, y = bill_depth_mm), alpha = 1 / 5)
## Warning: Removed 2 rows containing missing values or values outside the scale range
## (`geom_point()`).

ggplot(data = penguins) +
  geom_bin2d(mapping = aes(x = sex, y = bill_depth_mm))
## `stat_bin2d()` using `bins = 30`. Pick better value `binwidth`.
## Warning: Removed 2 rows containing non-finite outside the scale range
## (`stat_bin2d()`).

# install.packages("hexbin")
ggplot(data = penguins) +
  geom_hex(mapping = aes(x = sex, y = bill_depth_mm))
## Warning: Removed 2 rows containing non-finite outside the scale range
## (`stat_binhex()`).

ggplot(data = penguins, mapping = aes(x = sex, y = bill_length_mm)) + 
  geom_boxplot(mapping = aes(group = sex))
## Warning: Removed 2 rows containing non-finite outside the scale range
## (`stat_boxplot()`).

Patterns and models