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():geompoint(color="blue").
-
geombar()vsgeomcol():geombar()counts rows (likestat="count").geomcol()uses y-values directly. Usegeomcol()when your data already has the heights.
6. MCQs
Question 1
In ggplot2, aes() maps?
Question 2
geomcol() vs geombar()?
Question 3
facetwrap(~region) creates?
Question 4
reorder(x, y) in aes() sorts?
Question 5
alpha=0.5 in geompoint()?
Question 6
thememinimal() provides?
Question 7
ggsave("plot.png", dpi=300) creates?
Question 8
scaleycontinuous(labels=scales::comma) formats y-axis as?
Question 9
geomsmooth(method="lm") adds?
Question 10
coordflip() in bar chart?
7. Interview Questions
- Q: What is the Grammar of Graphics and how does ggplot2 implement it?
-
Q: When would you use
geomcol()vsgeombar()?
8. Summary
ggplot2 Grammar: data + aesthetics (aes()) + geometry (geom*()) + scales + theme. Core geometries: geompoint(), geomcol(), geomline(), geomhistogram(), geomboxplot(). Colors: inside aes() for mapped colors, outside for fixed. facetwrap() for small multiples. theme_minimal() for clean defaults. ggsave() for high-res export.