Example 03: Experimenting with geoms

library(tidyverse)
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr     1.1.4     ✔ readr     2.1.5
✔ forcats   1.0.0     ✔ stringr   1.5.1
✔ ggplot2   3.5.1     ✔ tibble    3.2.1
✔ lubridate 1.9.4     ✔ tidyr     1.3.1
✔ purrr     1.0.2     
── 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
library(gapminder)
library(palmerpenguins)

Penguin histograms

penguins |> 
  ggplot(mapping = aes(bill_length_mm)) + 
  geom_histogram()
`stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
Warning: Removed 2 rows containing non-finite outside the scale range
(`stat_bin()`).

penguins |> 
  drop_na(bill_length_mm) |> 
  ggplot(mapping = aes(x = bill_length_mm)) + 
  geom_histogram()
`stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

penguins |> 
  drop_na(bill_length_mm) |> 
  ggplot(mapping = aes(x = bill_length_mm)) + 
  geom_histogram(binwidth = 1)

penguins |> 
  drop_na(bill_length_mm) |> 
  ggplot(mapping = aes(x = bill_length_mm)) + 
  geom_histogram(binwidth = 1)

penguins |> 
  drop_na(bill_length_mm) |> 
  ggplot(mapping = aes(x = bill_length_mm, 
                       color = species)) + 
  geom_histogram(binwidth = 1)

penguins |> 
  drop_na(bill_length_mm) |> 
  ggplot(mapping = aes(x = bill_length_mm, 
                       fill = species)) + 
  geom_histogram(binwidth = 1)

penguins |> 
  drop_na(bill_length_mm) |> 
  ggplot(mapping = aes(x = bill_length_mm, 
                       fill = species)) + 
  geom_histogram(binwidth = 1, color = "black")

penguins |> 
  drop_na(bill_length_mm) |> 
  ggplot(mapping = aes(x = bill_length_mm, 
                       fill = species)) + 
  geom_histogram(binwidth = 1, color = "black") + 
  facet_wrap(~ species, ncol = 1)

penguins |> 
  drop_na(bill_length_mm) |> 
  ggplot(mapping = aes(x = bill_length_mm, 
                       fill = species)) + 
  geom_histogram(binwidth = 1, color = "black") + 
  facet_wrap(~ species, ncol = 1) + 
  guides(fill = "none") 

penguins |> 
  drop_na(bill_length_mm) |> 
  ggplot(mapping = aes(x = bill_length_mm, 
                       fill = species)) + 
  geom_histogram(binwidth = 1, color = "black") + 
  facet_wrap(~ species, ncol = 1) + 
  guides(fill = "none") +
  labs(x = "Bill Length (mm)", 
       y = "Count")