Week 4 · Tuesday, Oct 20 · 9:50-10:55 am · Self-guided
Work through one lesson on the Intro to R site, on your own:
By 10:55 you should have one proof-of-completion PDF downloaded, and a script that re-makes every plot in Positron.
Important
3 points, as always: 2 for the printout, 1 for Thursday’s discussion check.
1:30 pm, same room. DS 3 check, then every group presents.
If you finish the DS early, rehearse your 3 minutes out loud, with a timer, quietly. Not in the room if it disturbs others.
Allowed
?geom_point, ?themeNot allowed
Talking through an idea with a neighbor is fine. Reading their screen and typing what’s on it is not.
Draw the axes on paper before you write the code.
What goes on x, what goes on y, what changes colour, how many marks? Write it as a comment:
Note
Thursday’s discussion check will show you a plot from your printout and ask: “Which line of code made the points that colour? What happens if you move it?”
Open stat266a in Positron and create week04/ds04_notes.R:
gm. Does the plot look the way you expected?Tip
At 10:50, the restart test: Session → Restart R, source week04/ds04_notes.R. Every plot should be re-made, with no errors.
week04/ds04_notes.RIf you spend more than 10 minutes on one exercise, raise your hand. Being stuck is useful; being stuck for 40 minutes is not.
| Exercise | The skill |
|---|---|
| 1. GDP over time | Changing which column goes to which axis |
| 2. Colour by continent | Mapping a column to colour inside aes() |
| 3. Which layer is on top? | group, and layer order |
| 4. Fixed colour and size | Fixed properties outside aes(); log scale; lm line |
| 5. Shapes and one trend per continent | Inherited mappings; fixed shape |
| 6. Boxplots by continent | Subsetting first, then plotting; labels and themes |
Exercises 3, 5 and 6 are the core of the lesson and the ones we discuss on Thursday. The advanced part of 6 is last.
Exercise 1. You don’t need a new geom. You need to change what goes inside aes(). Which column is “time”? Which axis does time go on?
The plot will look strange: lots of points stacked at each year. That’s expected for a scatterplot of 12 years.
Exercise 2. Start from your p1 code, not from scratch. One addition, inside aes().
Then look at the plot and answer the question in a comment: which continent’s GDP grew fastest? Were you surprised?
Exercise 3. Two things to get right:
group = country, geom_line() draws one zig-zag through every row. Thursday’s “saw” slideThen swap the two layers and look. Can you see the difference? On which part of the plot?
Exercise 4. Click Run first and write down your colour and size.
Both are the same for every point, so where do they go: inside or outside aes()? If a legend appears with your colour’s name in it, you put it in the wrong place.
Exercise 5. You want one lm line per continent. geom_smooth() splits by whatever grouping it inherits. So where must colour = continent be: in ggplot(), or in geom_point()?
Count the lines when you’re done. How many should there be?
Exercise 6. Two steps, in this order:
gm_year: only the rows of gm from your year. Last week’s subsetting: [condition, ], with the comma. Check nrow(): how many countries should there be?gm_year: continent on x, GDP per capita on y, and the y labelAdvanced: Thursday’s “Themes and tweaks” slide.
By now you should be done with Exercises 1 to 3 and working on 4.
Behind? That’s fine. Priorities:
Done early? Walk over to someone who’s stuck and ask them to sketch their plot for you, on paper. Don’t tell them the answer.
At the bottom of the lesson page:
Warning
Do it now, in the room. The site stores your work in your browser: a cleared cache or a different laptop and it’s gone. Your week04/ds04_notes.R is your backup.
Upload to Canvas by Wednesday 11:59 pm
And by 1:00 pm today
Bring to Thursday’s lecture
Late DS: up to 3 days, 5% off per 24 hours. The lowest DS grade is dropped. The proposal is a hard deadline.
See you at 1:30 pm for the proposals. Come on time: the DS 3 check starts at 1:30, and the first group presents right after.

STAT 266A · Fall 2026 · UC Santa Cruz