slide mode

Dataviz of Gapminder

Yijia Lin

Loading data

We will load the dataset gapminder included in the R package {gapminder} “—” to change slides

library(gapminder)
gapminder <- gapminder::gapminder

Prerpocess data

We will filter just data from 2007

library(dplyr)
gapminder_2007<-
  gapminder |> 
  filter(year==2007)
gapminder_2007
# A tibble: 142 × 6
   country     continent  year lifeExp       pop gdpPercap
   <fct>       <fct>     <int>   <dbl>     <int>     <dbl>
 1 Afghanistan Asia       2007    43.8  31889923      975.
 2 Albania     Europe     2007    76.4   3600523     5937.
 3 Algeria     Africa     2007    72.3  33333216     6223.
 4 Angola      Africa     2007    42.7  12420476     4797.
 5 Argentina   Americas   2007    75.3  40301927    12779.
 6 Australia   Oceania    2007    81.2  20434176    34435.
 7 Austria     Europe     2007    79.8   8199783    36126.
 8 Bahrain     Asia       2007    75.6    708573    29796.
 9 Bangladesh  Asia       2007    64.1 150448339     1391.
10 Belgium     Europe     2007    79.4  10392226    33693.
# ℹ 132 more rows

Plot the data

library(ggplot2)
ggplot(gapminder_2007) +
  geom_point(aes(x = lifeExp, y = gdpPercap,
                 color = continent)) +
  ggthemes::scale_color_colorblind() +
  theme_minimal()