Course contentsShow
← Data Science
Lesson 1349 of 2,14534. Visualization with R and ggplot2Free lesson

Adding Geometric Objects with geom_* Functions

Add visual representations of data using geom_point(), geom_line(), geom_bar(), and other geometric layers.

Adding Geometric Objects with geom_* Functions

You'll learn how to turn abstract data mappings into actual visible shapes using ggplot2's geometric layer functions.

The Core Idea

In ggplot2, you've already established what data to plot and which variables map to visual properties (like x-position, y-position, color). But nothing appears on your canvas yet! That's where geom_ functions* come in—they tell ggplot2 how to draw your data: as points, lines, bars, or other shapes.

Think of it like building with LEGO: ggplot() sets up your base plate and defines what pieces you have available. The geom_* functions are the actual bricks you snap onto that base—each one creates a different visual structure.

Common Geometric Objects

geom_point() draws individual points (scatter plots)—perfect for showing relationships between continuous variables or plotting observations as dots.

geom_line() connects points with lines—ideal for time series or showing trends where the order matters.

geom_bar() creates bars—great for comparing categories or showing counts and totals.

Other geoms you'll encounter include geom_histogram(), geom_boxplot(), geom_smooth(), and dozens more. Each renders data differently but follows the same pattern: you add it as a layer to your base ggplot object.

How It Works

You build up your visualization by adding geoms with the + operator:

ggplot(data, aes(x = variable1, y = variable2)) + 
  geom_point()

This creates a scatter plot. Swap geom_point() for geom_line() and you get a line graph instead—same data, different representation.

Key Takeaway: Geom functions are the visual building blocks that transform your data and aesthetic mappings into actual marks on the plot—choose the geom that best represents your data's story.