Skip to main content

Data & setup

Data

All the data used in the course comes as a single zip file. Download it and unzip it into the folder you will work in, so that you have a data folder next to your scripts.

The folder contains:

File What it contains
penguins.csv Bill, flipper and body measurements for 344 penguins of three species
gapminder_2010.csv Income, health and population indicators for 167 countries in 2010
gapminder_1960_2010.csv The same indicators for every year from 1960 to 2010
finches.csv Beak and body measurements for Darwin’s finches

A suggested folder layout:

my-figures/
    data/
        penguins.csv
        ...
    figures/        (save your figures here)
    my_script.R     (or my_script.py)

Software

You only need one of the two languages. Choose whichever you use in your own work.

  1. Install R (version 4.2 or later).
  2. Install RStudio Desktop.
  3. Open RStudio and run this in the console to install the packages:
install.packages(c("tidyverse", "patchwork", "scales", "colorspace", "Hmisc"))
  1. Check everything works:
library(tidyverse)
ggplot(mtcars, aes(x = wt, y = mpg)) + geom_point()

If you see a scatter plot, you are ready.

  1. Install Python 3.10 or later, from python.org or with Miniforge.
  2. Install Visual Studio Code with the Python extension, or use JupyterLab.
  3. In a terminal, install the packages:
pip install pandas plotnine

or, with conda:

conda install -c conda-forge pandas plotnine
  1. Check everything works:
import pandas as pd
from plotnine import ggplot, aes, geom_point
from plotnine.data import mtcars

p = ggplot(mtcars, aes(x="wt", y="mpg")) + geom_point()
p.show()

If you see a scatter plot, you are ready.

NoteCan’t install software?

You can follow the R materials in Posit Cloud and the Python materials in Google Colab through a web browser. Upload the data folder to your project first.

Why ggplot2 and plotnine?

Both packages implement the same grammar of graphics, so the code looks almost identical in the two languages. The main difference is that Python puts column names in quotes:

ggplot(penguins, aes(x = bill_length_mm, y = bill_depth_mm)) +
  geom_point()
(ggplot(penguins, aes(x="bill_length_mm", y="bill_depth_mm"))
 + geom_point())

Learn the ideas once, and you can use them in either language.