توضیح 1
The live starter code is self-contained and uses only runner-compatible functions.
Loading
درس 8 از 22
Use layers, scales, facets, labels, and accessible encodings to make defensible statistical graphics.
Motivation
A chart is an analytical argument made with position, scale, colour, and annotation; design choices determine the comparisons readers can make.
Why this matters
Use layers, scales, facets, labels, and accessible encodings to make defensible statistical graphics.
Packages and data
ggplot2 4.0.3 in the book; base graphics in the live runner.
توضیح 1
The live starter code is self-contained and uses only runner-compatible functions.
توضیح 2
Book-only outputs are labelled when the separate source dataset or advanced package was not supplied.
توضیح 3
R code, paths, function names, and formulas remain left-to-right in every locale.
اصطلاحات
A variable-to-visual relationship declared inside aes().
date to x, inflation to y
A fixed visual property outside aes().
colour = '#08747D'
Repeated aligned panels that avoid misleading dual axes.
One panel per series
نمادگذاری و فرمولها
graphic = data + mappings + geoms + scales + coordinates + facets + theme
Separating components makes graphical intent reviewable.
مثال حلشده
سناریو
How does a zero baseline change perception of annual means?
بررسی با R
annual <- c('2022'=6.8,'2023'=3.9,'2024'=2.4,'2025'=2.2)
print(range(annual))
barplot(annual, ylim=c(0,7), col='#08747D', ylab='Inflation (%)')
abline(h=2, lty=2)A 2% reference supports policy context without implying a forecast. Limitation: Annual averaging hides within-year movement and does not explain causes.
Visual
The same four means shown from a zero baseline.
ارتباط با R
Run the self-contained starter code in the protected STATLAB R runner. The code prints an auditable result and avoids network or unrestricted file access.
Live R Lab
Run a self-contained example, verify its output, and explain one limitation for data visualization with ggplot2.
Ready to run
Common mistake
A truncated bar baseline exaggerates small differences because bar length implies ratios.
STATLAB Tip
Write the intended one-sentence takeaway before polishing; remove elements that do not support it or an essential qualification.
تمرین هدایتشده
سناریو
Redesign the bars as a dot plot with a 2% reference line and draft alt text.
Compare your result with the definition, units, and model assumptions—not only with a target number.
Exercises
Complete these without looking at the selected solutions. More than one defensible program may exist.
توضیح 1
Create a labelled line chart.
توضیح 2
Compare fixed and free facet scales.
توضیح 3
Draft alt text naming chart type, variables, pattern, and reference.
Selected solutions
These are compact solution routes. Confirm dimensions, units, and any changed modelling choices.
توضیح 1
plot(dates, x, type='l'); abline(h=2,lty=2)
توضیح 2
Fixed scales compare magnitude; free scales reveal within-series shape.
توضیح 3
Good alt text communicates the main pattern without listing every point.
Chapter summary
Use layers, scales, facets, labels, and accessible encodings to make defensible statistical graphics.
توضیح 1
Build graphics from explicit components.
توضیح 2
Map variables; set constants.
توضیح 3
Axes determine valid comparisons.
توضیح 4
Contrast, labels, and redundant encodings improve access.
اصطلاحات
initialize graphic
Use in Data Visualization with ggplot2.
map variables
Use in Data Visualization with ggplot2.
ordered path
Use in Data Visualization with ggplot2.
titles and units
Use in Data Visualization with ggplot2.
References and provenance
Safavi (2026), Chapter 8; ggplot2 documentation. Student notes: Mohammad Safavi, Ph.D., STATLAB Academy, Version 1.0.
منبع
The authoritative 125-page English PDF accompanies this native lesson.
دریافتبازاندیشی
Name the assumption, evidence you would seek, and how the recommendation might change.
ارزیابی پایانی