Advanced Graphics and Programming

In this unit, you will learn how to add and modify basic plots, create functions and learn some programming tricks.

Follow the links to each lecture, lab, and reading.

Scroll down to download the SWIRL lessons.

Lesson 1. How to add stuff to plots


Learning Goals:

SWIRL: Plotting More Data

Lab: Unit 5: Lab 1

Reading: Bestiary of Graphics

Functions: abline(), text(), mtext(), points(), legend(), mfrow(), mfcol(),

Lesson 2. How to encoding values in graphics

Lecture: Encoding values in color

Learning Goals:

SWIRL: Plotting Colours

Lab: Unit 5: Lab 2

Reading: Exporting graphics

Functions: palette(), pdf(), png()

Lesson 3. How to write less code

Lecture: Writing your own functions

Learning Goals:

SWIRL: Writing functions

Lab: Unit 5: Lab 3

Reading: Best practice for writing R code

Functions: function()

Lesson 4. How to automate your work

Lecture: Control Structures slides

Learning Goals:

SWIRL: Loops

Lab: Unit 5: Lab 4

Reading: Crawley, M. The R Book Ch 2. Essentials of the R Language. 2.10 Loops and repeats

Functions: if(), else(), for() {}, while() {}, repeat {}, break, next

Lesson 5: How to sample and generate random values

Lecture: Sampling.

Learning Goals:

SWIRL: Sampling and simulation

Lab: Unit 5: Recap

Reading: Crawley, M. The R Book Ch 2. Essentials of the R Language. 2.9 Random numbers, shuffling, and sampling

Functions: sample(), rbinom(), rnorm(),