Skip to content
# Load the Tidyverse
library(tidyverse)

# Read in the gapminder file
gapminder <- read.csv("datasets/gapminder.csv", sep = "\t")

Introduction to the Tidyverse

Run the hidden code cell below to import the data used in this course.

Take Notes

Add notes about the concepts you've learned and code cells with code you want to keep.

Add your notes here

library(gapminder)
library(dplyr)
library(ggplot2)

gapminder_1952 <- gapminder %>%
  filter(year == 1952)

# filtering, mutating, arranging and then plotting
gapminder %>%
    filter(year == 2007) %>%
    mutate(lifeExpMonths = lifeExp *12 ) %>%
    arrange(desc(lifeExpMonths))

ggplot(gapminder, aes(x = lifeExpMonths, y = year)) + geom_point()

# adding colour

ggplot(gapminder, aes(x = lifeExpMonths, y = year, colour = continent)) + geom_point()

# Summarising the median GDP and median life expectancy per continent in 2007
gapminder %>%
    filter(year == 2007) %>%
    group_by(continent) %>%
    summarise(medianLifeExp = median(lifeExp), medianGdpPercap = median(gdpPercap))

# How to graph a scatter plot, line graph, bar charts, histograms and boxplot

ggplot(gapminder, aes(x = lifeExpMonths, y = year)) + geom_point() #scatter plot
ggplot(gapminder, aes(x = lifeExpMonths, y = year)) + geom_line() #line graph
ggplot(gapminder, aes(x = lifeExpMonths, y = year)) + geom_col() #bar chart
ggplot(gapminder, aes(x = lifeExpMonths, y = year)) + geom_histogram(bins = ...) #histogram
ggplot(gapminder, aes(x = lifeExpMonths, y = year)) + geom_bixplot() #boxplot