| Block | Teaching | Activity | Output to keep |
|---|---|---|---|
| Question and source | 10 min | 5 min | A plot specification |
| Distributions | 10 min | 5 min | A checked display |
| Relationships | 10 min | 5 min | A scoped comparison |
| Break | — | 10 min break | — |
| Groups and facets | 10 min | 5 min | A subgroup display |
| Scales and missingness | 10 min | 5 min | An audited figure |
| Save and interpret | 10 min | 5 min | A figure and caption |
| Total | 60 min | 30 min | 100 min including the break |
This is lesson 6 of eight. Each five-minute activity includes a room response and debrief. Save work before the ten-minute break; use a practice copy and keep original inputs unchanged.
Open the shared project from Additional Material, complete lesson 5 and load the existing gapminder and ggplot2 packages. Use the public historical data and retain the same year, units and keys in comparisons.
Each row in year_data is a country in one recorded year. The full data repeat countries over time. State which level is plotted; a country-level association cannot establish individual outcomes or causation.
| Question | Useful starting display | Check |
|---|---|---|
| How are country values distributed? | Histogram, box plot or individual-value display | Observed count and bin/group choices |
| How do two quantities vary together? | Scatter plot | Paired observations, units and axes |
| How do groups differ descriptively? | Facets or grouped distributions | Comparable scales and denominators |
| How do selected countries change over time? | Labelled lines | Country identity and recorded years |
Goal: match a display to a defined question Input: the 2007 table and the full dataset Work in pairs: one operates and one checks; swap roles between tasks.
Keep: a plot specification. If access fails: annotate the instructor’s displayed input and output with the same decisions and checks.
The chart type follows the intended comparison. Define the source and level before using an attractive plotting template.

Compare a different bin width and an individual-value or box-plot display. Changing bins changes appearance, not the measurements. Disclose missing observations if present; do not remove an extreme value simply because it changes the shape.
Goal: connect displayed counts to observed records Input: the histogram and one alternative bin width Work in pairs: one operates and one checks; swap roles between tasks.
Keep: the two views and count check. If access fails: annotate the instructor’s displayed input and output with the same decisions and checks.
A presentation change can alter perceived shape. The denominator and data selection must remain visible.

Read the data documentation for the economic measure’s definition. A log scale can help display a wide range, but must be labelled and appropriate for the observed values. A fitted smooth is an exploratory summary, not an explanation of cause.
Goal: verify that the two plotted measurements are paired Input: the 2007 relationship plot Work in pairs: one operates and one checks; swap roles between tasks.
Keep: a checked point and qualified interpretation. If access fails: annotate the instructor’s displayed input and output with the same decisions and checks.
A scale affects visual spacing. It does not alter the source values or establish a causal mechanism.
Save the plot specification and source checks.

Set a seed before saving a plot that uses random jitter when exact reproduction matters. Labels and position identify groups without depending only on colour. Groups contain different numbers of countries; an unweighted country comparison is not a population-weighted one.
Goal: retain values, grouping and denominators Input: the grouped display Work in pairs: one operates and one checks; swap roles between tasks.
Keep: a subgroup display and caveat. If access fails: annotate the instructor’s displayed input and output with the same decisions and checks.
Grouping clarifies structure but can hide within-group variation. A named continent is not a causal explanation.
The original axis-limit examples in the reference bank are retained. Scale limits can remove observations before a statistic such as smoothing is computed; visual zooming with coord_cartesian() serves a different purpose. Inspect warnings and compare the input and plotted records.

The range is a declared teaching display choice, not a rule for excluding research observations. Check units, sources, dates, legend labels and missingness in the caption.
Goal: identify whether a display choice removes information Input: the full plot, zoomed view and retained limit examples Work in pairs: one operates and one checks; swap roles between tasks.
Keep: an audit note and revised caption. If access fails: annotate the instructor’s displayed input and output with the same decisions and checks.
A plot must disclose its selection and presentation choices. Inspect warnings rather than suppressing them to obtain a tidy image.
Run these commands from the extracted shared project folder, which contains analysis.R and its data directory.

Use ggsave() with a named practice destination, explicit width/height and units. Inspect the saved file, compare one value with its source and write an interpretation containing the year, units, observation level and limitation. Lesson 7 places this output in a computational research notebook.
Goal: produce a checked figure and explanatory caption Input: the shared project selection and plot Work in pairs: one operates and one checks; swap roles between tasks.
Keep: the figure, source check and caption. If access fails: annotate the instructor’s displayed input and output with the same decisions and checks.
An exported image needs context to travel beyond its author. Keep the code and source selection with it.
These retained extensions use gridExtra and ggExtra; prepare them using Setup before choosing those examples. Save only to a practice output folder and inspect destinations before rerunning exports.
The existing plotting variants are preserved below for further practice, outside the core plan. They use the full gapminder table and sometimes pool repeated country observations. Inspect that scope and all warnings before interpretation. The original data manipulations and worked exercise bank remain in lesson 5.

`stat_bin()` using `bins = 30`. Pick better value `binwidth`.





`geom_smooth()` using method = 'gam' and formula = 'y ~ s(x, bs = "cs")'

`geom_smooth()` using method = 'loess' and formula = 'y ~ x'

The existing scale limits below remove out-of-range values before statistical layers are calculated. This can change a smooth as well as the visible points. Inspect warnings and exclusions. If you intend only to zoom the view, the ggplot2 coordinate documentation explains coord_cartesian(); the example limits are retained here so this distinction is visible.
`geom_smooth()` using method = 'gam' and formula = 'y ~ s(x, bs = "cs")'
Warning: Removed 496 rows containing non-finite outside the scale range
(`stat_smooth()`).
Warning: Removed 496 rows containing missing values or values outside the scale range
(`geom_point()`).





`geom_smooth()` using method = 'gam' and formula = 'y ~ s(x, bs = "cs")'






Save a plot to a file using ggsave.
[1] "/home/vsts/work/1/s/training_site/courses/applied_R/episodes"
Saving 7 x 5 in image
`geom_smooth()` using method = 'gam' and formula = 'y ~ s(x, bs = "cs")'
You can specify, inspect and save figures with source checks and limitations. Next, keep narrative, code and results together in a notebook.
