CHAPTER 16
Beginner
Data Visualization with ggplot2
Updated: May 18, 2026
5 min read
# CHAPTER 16
Data Visualization with ggplot2
1. Chapter Introduction
ggplot2's Grammar of Graphics revolutionized data visualization — it defines charts as layers of data, aesthetics, and geometries. Once understood, any chart becomes buildable in a consistent, logical way.2. Grammar of Graphics Fundamentals
r
3. Essential Chart Types
r
4. Faceting and Themes
r
5. Common Mistakes
-
aes(color="blue")vscolor="blue"outside aes(): Insideaes(),color="blue"maps a variable named "blue" (wrong). Set fixed colors outsideaes():geom_point(color="blue").
-
geom_bar()vsgeom_col():geom_bar()counts rows (likestat="count").geom_col()uses y-values directly. Usegeom_col()when your data already has the heights.
6. MCQs
Question 1
In ggplot2, aes() maps?
Question 2
geom_col() vs geom_bar()?
Question 3
facet_wrap(~region) creates?
Question 4
reorder(x, y) in aes() sorts?
Question 5
alpha=0.5 in geom_point()?
Question 6
theme_minimal() provides?
Question 7
ggsave("plot.png", dpi=300) creates?
Question 8
scale_y_continuous(labels=scales::comma) formats y-axis as?
Question 9
geom_smooth(method="lm") adds?
Question 10
coord_flip() in bar chart?
7. Interview Questions
- Q: What is the Grammar of Graphics and how does ggplot2 implement it?
-
Q: When would you use
geom_col()vsgeom_bar()?
8. Summary
ggplot2 Grammar: data + aesthetics (aes()) + geometry (geom_*()) + scales + theme. Core geometries: geom_point(), geom_col(), geom_line(), geom_histogram(), geom_boxplot(). Colors: inside aes() for mapped colors, outside for fixed. facet_wrap() for small multiples. theme_minimal() for clean defaults. ggsave() for high-res export.