library(ggplot2)
ggplot(data = mpg, aes(x = displ, y = hwy)) +
geom_point()
ggplot basicsSummary for Lecture 3,4,5 DANL 310
Jordan A
February 12, 2025
ggplot2 is a powerful and flexible R package for creating data visualizations. It follows the Grammar of Graphics approach, allowing users to layer components to build complex plots systematically.
To create a ggplot, you start with the ggplot() function, specifying a dataset and mapping aesthetics using aes().
Layers such as geom_point(), geom_line(), and geom_bar() define how data is represented.
Themes, scales, and labels allow customization.
Faceting creates small multiples based on categorical variables.
ggplot2 provides an intuitive way to build visualizations layer by layer. Mastering these basics sets a strong foundation for more advanced customizations and analyses.