Geometric Objects (geoms)
What you'll learn: How geoms determine the visual shape of your data in ggplot2 and why choosing the right geom depends on your data structure.
The Core Idea
In the grammar of graphics, geometric objects (geoms) are the actual marks you see on a plot—the visual representation of your data. Think of geoms as the "nouns" of your visualization: points, lines, bars, boxes, and more. While aesthetic mappings tell ggplot2 which variables to use, geoms decide how those variables appear visually.
The same dataset can look completely different depending on the geom you choose. A dataset with x and y coordinates could become:
- Points (
geom_point) for scatter plots showing individual observations - Lines (
geom_line) connecting observations in sequence - Bars (
geom_barorgeom_col) showing magnitudes as vertical rectangles
Geoms and Data Structure
The geom you select should match your data structure and analytical question:
- Continuous relationships? Use
geom_pointorgeom_line - Categorical comparisons? Use
geom_barorgeom_col - Distributions? Use
geom_histogramorgeom_boxplot
Some geoms perform statistical transformations automatically. For example, geom_bar counts observations, while geom_col uses values directly from your data. Understanding this relationship prevents confusion when your plot doesn't match expectations.
Geoms can also be layered—you might add both points and a line to show raw data plus a trend, creating a richer, multi-layered visualization.
Key Takeaway: Geoms translate your data into visual marks; choosing the right geom means matching the geometric shape (points, lines, bars) to your data structure and the story you want to tell.