Leftover tidbits recitation

Week 13


Jessica Cooperstone


Today’s recitation materials are on a bunch of stuff I thought was interesting but didn’t fit specifically into any of the other lessons. This includes some cool ggplot extension packages we haven’t gone over yet, and heatmaps that utilize base R plotting.

Load libraries

Loading the libraries that are for each section. Individual libraries are before each section so you can see which go with what plot types.

library(tidyverse) # for everything
library(gghighlight) # for highlighting
library(gganimate) # animating plots
library(ggrepel) # for text/label repelling
library(magick) # for gif rendering
library(scales) # for easy scaling
library(plotly) # for ggplotly
library(glue) # for easy pasting

library(gapminder) # for data for viz2

Really start using an Rproject 📽️

A cartoon of a cracked glass cube looking frustrated with casts on its arm and leg, with bandaids on it, containing “setwd”, looks on at a metal riveted cube labeled “R Proj” holding a skateboard looking sympathetic, and a smaller cube with a helmet on labeled “here” doing a trick on a skateboard.

Artwork by @allison_horst

If you don’t have a Rproject for class, set one up.

Visualization 1

We are going to interrogate a dataset from Gapminder that includes information about Happiness Scores collected across different countries and years.

Create a visualization that shows the happiness scores for all countries from 2008 to 2010. Highlight in some way the top 3 countries with the highest happiness scores per continent.

I’ve put the data on Github so you can easily download it with the code below. Note, the question asks you to make a plot considering continent so I’ve also provided you a key that has each country, and the continent to which it belows for you to join together.

Load data

happiness <- read_csv("https://github.com/jcooperstone/dataviz-site/raw/master/4_12_leftovers/data/hapiscore_whr.csv")

country_continent <- read_csv("https://github.com/jcooperstone/dataviz-site/raw/master/4_12_leftovers/data/country_continent.csv")

Visualization 2

Recreate a plot in the vein of the one here. You can make the same interactive plot (use the data from 2007, which is slightly older and different from what you see in the online plot), or choose to animate it over year. Or do both.

Use the data gapminder::gapminder which you can access from R.

Back to top