Faceting for Subplots in R with ggplot2
📖 Scenario: You are a data analyst working with a dataset of car models and their fuel efficiency. You want to create separate plots for each car manufacturer to compare their fuel efficiency visually.
🎯 Goal: Build a faceted plot using ggplot2 in R that shows fuel efficiency for different car models, separated by manufacturer in subplots.
📋 What You'll Learn
Create a data frame called
cars with columns manufacturer, model, and mpg with exact valuesCreate a ggplot object called
p with model on x-axis and mpg on y-axisAdd points to the plot using
geom_point()Use
facet_wrap() to create subplots by manufacturerPrint the plot object
p💡 Why This Matters
🌍 Real World
Faceting helps compare groups side-by-side in separate plots, useful in data analysis and reporting.
💼 Career
Data analysts and scientists use faceting to explore and present data clearly across categories.
Progress0 / 4 steps