3.3 Bar chart: geom_bar()

  • Makes a bar plot.
ggplot(diamonds, aes(cut)) +
  geom_bar()

  • What’s up with stat = "identity"?
    • The default stat is to count values.
    • Setting this parameter leaves the data unchanged.
# Why, though? Perhaps I want to do my own aggregation
data_diamond_count <- 
  diamonds |>
  count(cut, name = "count")

ggplot(data_diamond_count, aes(cut, count)) +
  geom_bar(stat = "identity")