Data Visualization and Manipulation

Part 1: Introduction to tidyverse

Tidyverse

install.packages("tidyverse")
library(tidyverse)

(Remember, you only need to do this once!)

Pipes

# install.packages("gapminder")
library(gapminder)
data(gapminder)

Pipes

Let’s preview the data.

data(gapminder)
head(gapminder)
## # A tibble: 6 × 6
##   country     continent  year lifeExp      pop gdpPercap
##   <fct>       <fct>     <int>   <dbl>    <int>     <dbl>
## 1 Afghanistan Asia       1952    28.8  8425333      779.
## 2 Afghanistan Asia       1957    30.3  9240934      821.
## 3 Afghanistan Asia       1962    32.0 10267083      853.
## 4 Afghanistan Asia       1967    34.0 11537966      836.
## 5 Afghanistan Asia       1972    36.1 13079460      740.
## 6 Afghanistan Asia       1977    38.4 14880372      786.

Pipes

Let’s preview the data.

data(gapminder)
head(gapminder, 10)
## # A tibble: 10 × 6
##    country     continent  year lifeExp      pop gdpPercap
##    <fct>       <fct>     <int>   <dbl>    <int>     <dbl>
##  1 Afghanistan Asia       1952    28.8  8425333      779.
##  2 Afghanistan Asia       1957    30.3  9240934      821.
##  3 Afghanistan Asia       1962    32.0 10267083      853.
##  4 Afghanistan Asia       1967    34.0 11537966      836.
##  5 Afghanistan Asia       1972    36.1 13079460      740.
##  6 Afghanistan Asia       1977    38.4 14880372      786.
##  7 Afghanistan Asia       1982    39.9 12881816      978.
##  8 Afghanistan Asia       1987    40.8 13867957      852.
##  9 Afghanistan Asia       1992    41.7 16317921      649.
## 10 Afghanistan Asia       1997    41.8 22227415      635.

Pipes

Let’s preview the data.

data(gapminder)
head(gapminder, 15)
## # A tibble: 15 × 6
##    country     continent  year lifeExp      pop gdpPercap
##    <fct>       <fct>     <int>   <dbl>    <int>     <dbl>
##  1 Afghanistan Asia       1952    28.8  8425333      779.
##  2 Afghanistan Asia       1957    30.3  9240934      821.
##  3 Afghanistan Asia       1962    32.0 10267083      853.
##  4 Afghanistan Asia       1967    34.0 11537966      836.
##  5 Afghanistan Asia       1972    36.1 13079460      740.
##  6 Afghanistan Asia       1977    38.4 14880372      786.
##  7 Afghanistan Asia       1982    39.9 12881816      978.
##  8 Afghanistan Asia       1987    40.8 13867957      852.
##  9 Afghanistan Asia       1992    41.7 16317921      649.
## 10 Afghanistan Asia       1997    41.8 22227415      635.
## 11 Afghanistan Asia       2002    42.1 25268405      727.
## 12 Afghanistan Asia       2007    43.8 31889923      975.
## 13 Albania     Europe     1952    55.2  1282697     1601.
## 14 Albania     Europe     1957    59.3  1476505     1942.
## 15 Albania     Europe     1962    64.8  1728137     2313.

Some Summary Statistics

Below are the mean, median and standard deviation of the variable “pop”.

# Mean
mean(gapminder$pop)
## [1] 29601212
# Median
median(gapminder$pop)
## [1] 7023596
# Standard Deviation
sd(gapminder$pop)
## [1] 106157897

Functions in Functions

What if we want the mean log population within our data set? Using base R, we might type

mean(log(gapminder$pop))
## [1] 15.76611

With pipes, we can use

gapminder$pop %>%
  log() %>%
  mean()
## [1] 15.76611

Functions in Functions

Both of these are acceptable. However, when we start adding more and more functions, pipes can make your code much easier and more natural to read.

mean(gapminder$pop)
## [1] 29601212

With pipes, we can use

gapminder$pop %>%
  mean()
## [1] 29601212

Filtering Data

head(gapminder$country == "China" & gapminder$year >= 1970)
## [1] FALSE FALSE FALSE FALSE FALSE FALSE

Filtering Data

china_1980 <- gapminder %>% 
  select(country, year) %>%
filter(country == "China" & year >= 1970)
china_1980
## # A tibble: 8 × 2
##   country  year
##   <fct>   <int>
## 1 China    1972
## 2 China    1977
## 3 China    1982
## 4 China    1987
## 5 China    1992
## 6 China    1997
## 7 China    2002
## 8 China    2007

Part 2: Data Visualization

ggplot2

Data Visualization

# install.packages("ggplot2")
# library(ggplot2)
ggplot(data = gapminder) 

Data Visualization

ggplot(data = gapminder,
       aes(x = year, y = lifeExp)) 

Data Visualization

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

Data Visualization

ggplot(data = gapminder,
       aes(x = year, y = lifeExp)) +
  geom_point(color = "red", size = 0.75) 

Data Visualization

ggplot(data = gapminder,
       aes(x = year, y = lifeExp)) +
  geom_point(color = "blue", size = 0.75) 

Data Visualization

ggplot(data = gapminder,
       aes(x = year, y = lifeExp, group = country)) +
  geom_line(color = "red", size = 0.75) 
## Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
## ℹ Please use `linewidth` instead.

Data Visualization

ggplot(data = gapminder,
       aes(x = year, y = lifeExp, group = country, color = continent)) +
  geom_line(size = 0.4) 

Data Visualization

ggplot(data = gapminder,
       aes(x = year, y = lifeExp, group = country, color = continent)) +
  geom_line(size = 0.4) + 
geom_smooth(aes(group = continent), 
              se = FALSE, size = 1.5, 
              color = "black", 
              method = "loess") +
  facet_wrap(~ continent) 
## `geom_smooth()` using formula = 'y ~ x'

Data Visualization

Data Visualization

ggplot(data = gapminder,
       aes(x = year, y = lifeExp,
           group = country,
           color = continent)) + 
  geom_line(size = 0.5) +
  geom_smooth(aes(group = continent), 
              se = FALSE, size = 1.5, 
              color = "black", 
              method = "loess") +
  facet_wrap(~ continent) +
  labs(title = "Life expectancy over time by continent", 
       x = "Year", y = "Life Expectancy", 
       legend = "Continent")

Data Visualization

ggplot(data = gapminder,
       aes(x = year, y = lifeExp,
           group = country,
           color = continent)) + 
  geom_line(size = 0.5) +
  geom_smooth(aes(group = continent), 
              se = FALSE, size = 1.5, 
              color = "black", 
              method = "loess") +
  facet_wrap(~ continent) +
  labs(title = "Life expectancy over time by continent", 
       x = "Year", y = "Life Expectancy", 
       legend = "Continent") 

Data Visualization

ggplot(data = gapminder,
       aes(x = year, y = lifeExp,
           group = country,
           color = continent)) + 
  geom_line(size = 0.5) +
  geom_smooth(aes(group = continent), 
              se = FALSE, size = 1.5, color = "black", method = "loess") +
  facet_wrap(~ continent) +
  labs(title = "Life expectancy over time by continent", 
       x = "Year", y = "Life Expectancy") +
  theme(plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
        legend.position = "none") 

Data Visualization

Great, that looks good! Now we can store it as an object.

lifeExp_plot <- ggplot(data = gapminder, 
                       aes(x = year, y = lifeExp,
                           group = country,
                           color = continent)) + 
  geom_line(size = 0.5) +
  geom_smooth(aes(group = continent), 
              se = FALSE, size = 1.5, color = "black", method = "loess") +
  facet_wrap(~ continent) +
  labs(title = "Life expectancy over time by continent", 
       x = "Year", y = "Life Expectancy") +
  theme_bw(base_size = 16) + 
  theme(plot.title = element_text(hjust = 0.5, face = "bold"), 
        legend.position = "none",
        axis.text.x = element_text(angle = 45, hjust = 1, vjust = 1),
        panel.spacing.x = unit(0.75, "cm")) 

Data Visualization

Data Visualization

ggplot(data = gapminder, 
       aes(x = lifeExp))

Data Visualization

ggplot(data = gapminder, 
       aes(x = lifeExp)) + 
  geom_histogram()
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

Data Visualization

ggplot(data = gapminder, 
       aes(x = lifeExp)) + 
  geom_histogram(binwidth = 1, 
                 color = "black", 
                 fill = "lightblue") 

Data Visualization

ggplot(data = gapminder, 
       aes(x = lifeExp)) + 
  geom_histogram(binwidth = 1, 
                 color = "black", 
                 fill = "lightblue") +
  theme_bw(base_size = 20) +
  labs(x = "Life Expectancy", 
       y = "Count")

Data Visualization

ggplot(data = gapminder, 
       aes(x = continent, y = lifeExp)) 

Data Visualization

ggplot(data = gapminder, 
       aes(x = continent, y = lifeExp)) + 
geom_boxplot()

Data Visualization

ggplot(data = gapminder, 
       aes(x = continent, y = lifeExp)) + 
geom_boxplot(fill = "lightblue")

Data Visualization

ggplot(data = gapminder, 
       aes(x = continent, y = lifeExp)) + 
geom_boxplot(fill = "lightblue") + 
    labs(title = "Life expectancy by Continent", 
       x = "", 
       y = "") +
  theme(plot.title =
          element_text(hjust = 0.5)) +
  ylim(c(20, 85)) 

Data Visualization

ggplot(data = gapminder, 
       aes(x = continent, y = lifeExp)) + 
geom_boxplot(fill = "lightblue") + 
    labs(title = "Life expectancy by Continent", 
       x = "", 
       y = "") +
  theme(plot.title =
          element_text(hjust = 0.5)) +
  ylim(c(0, 85)) 

Data Visualization Suggestions

*Don’ts

*Do’s

Data Visualization cheatsheet

What plot to use?

One numeric variable: Histogram

ggplot(gapminder, aes(x = lifeExp)) + 
  geom_histogram() + 
  labs(x = "Life Expectancy",
       y = "Count",
       title = "Distribution of Life Expectancy") + 
  theme_bw(base_size = 16) + 
  theme(plot.title = 
          element_text(hjust = 0.5)) 

One numeric variable: Boxplot

ggplot(gapminder, aes(y = lifeExp)) + 
  geom_boxplot() + 
  labs(x = "",
       y = "Life Expectancy",
       title = "Distribution of Life Expectancy") + 
  theme_bw(base_size = 16) + 
  theme(plot.title = 
          element_text(hjust = 0.5),
        axis.ticks.x = element_blank(),
        axis.text.x = element_blank()) +
  ylim(c(0,90))

One categorical variable: Bar chart

ggplot(gapminder, aes(x = continent)) + 
  geom_bar() + 
  labs(x = "Continent",
       y = "Count",
       title = "Distribution of Continent") + 
  theme_bw(base_size = 16) + 
  theme(plot.title = 
          element_text(hjust = 0.5)) 

One numeric and one categorical variable

Here, we have multiple observations for each category.

ggplot(gapminder, aes(x = continent, y = lifeExp)) + 
  geom_boxplot() + 
  labs(x = "Continent",
       y = "Life Expectancy",
       title = "Life Expectancy by Continent") + 
  theme_bw(base_size = 16) + 
  theme(plot.title = 
          element_text(hjust = 0.5)) 

One numeric and one categorical variable

mean_lifeExp <- gapminder %>%
  group_by(continent) %>%
  summarise(mean_lifeExp = mean(lifeExp))

ggplot(mean_lifeExp, aes(x = continent, y = mean_lifeExp)) + 
  geom_bar(stat = "identity") + 
  labs(x = "Continent",
       y = "Mean Life Expectancy",
       title = "Mean Life Expectancy by Continent") + 
  theme_bw(base_size = 16) + 
  theme(plot.title = 
          element_text(hjust = 0.5)) 

Two numeric variables: scatterplot

ggplot(gapminder, aes(y = lifeExp, x = log(gdpPercap))) + 
  geom_point() + 
  labs(y = "Life expectancy",
       x = "Log GDP per capita",
       title = "Life Expectancy by Log GDP per capita") + 
  ylim(c(0,90)) + 
  theme_bw(base_size = 16) + 
  theme(plot.title = 
          element_text(hjust = 0.5)) 

Two categorical variables

gapminder <- gapminder %>% 
  mutate(lifeExpCat = ifelse(lifeExp > 60, TRUE, FALSE))
ggplot(gapminder, aes(x = continent, fill = lifeExpCat)) + 
  geom_bar() + 
  xlab("Continent") + 
  ylab("Count") + 
  labs(fill = "Life Exp. > 60") + 
  ggtitle("Distribution of Continent and Life Expectancy") + 
  theme_bw(base_size = 16) + 
  theme(plot.title = 
          element_text(hjust = 0.5)) 

Part 3: Data Manipulation

Recall Data

Let’s preview the data.

data(gapminder)
head(gapminder)
## # A tibble: 6 × 6
##   country     continent  year lifeExp      pop gdpPercap
##   <fct>       <fct>     <int>   <dbl>    <int>     <dbl>
## 1 Afghanistan Asia       1952    28.8  8425333      779.
## 2 Afghanistan Asia       1957    30.3  9240934      821.
## 3 Afghanistan Asia       1962    32.0 10267083      853.
## 4 Afghanistan Asia       1967    34.0 11537966      836.
## 5 Afghanistan Asia       1972    36.1 13079460      740.
## 6 Afghanistan Asia       1977    38.4 14880372      786.

select(): Column selection

gapminder %>% 
  select(lifeExp, gdpPercap)
## # A tibble: 1,704 × 2
##    lifeExp gdpPercap
##      <dbl>     <dbl>
##  1    28.8      779.
##  2    30.3      821.
##  3    32.0      853.
##  4    34.0      836.
##  5    36.1      740.
##  6    38.4      786.
##  7    39.9      978.
##  8    40.8      852.
##  9    41.7      649.
## 10    41.8      635.
## # … with 1,694 more rows
## # ℹ Use `print(n = ...)` to see more rows

select(): Column selection

Use select() to choose certain columns. We can also use select() to remove certain columns by putting a - symbol in front.

gapminder %>% 
  select(-lifeExp, -gdpPercap)
## # A tibble: 1,704 × 4
##    country     continent  year      pop
##    <fct>       <fct>     <int>    <int>
##  1 Afghanistan Asia       1952  8425333
##  2 Afghanistan Asia       1957  9240934
##  3 Afghanistan Asia       1962 10267083
##  4 Afghanistan Asia       1967 11537966
##  5 Afghanistan Asia       1972 13079460
##  6 Afghanistan Asia       1977 14880372
##  7 Afghanistan Asia       1982 12881816
##  8 Afghanistan Asia       1987 13867957
##  9 Afghanistan Asia       1992 16317921
## 10 Afghanistan Asia       1997 22227415
## # … with 1,694 more rows
## # ℹ Use `print(n = ...)` to see more rows

select(): Column selection

names(gapminder)
## [1] "country"   "continent" "year"      "lifeExp"   "pop"       "gdpPercap"
gapminder %>%
  select(starts_with("co")) %>%
  head()
## # A tibble: 6 × 2
##   country     continent
##   <fct>       <fct>    
## 1 Afghanistan Asia     
## 2 Afghanistan Asia     
## 3 Afghanistan Asia     
## 4 Afghanistan Asia     
## 5 Afghanistan Asia     
## 6 Afghanistan Asia

select(): Column selection

names(gapminder)
## [1] "country"   "continent" "year"      "lifeExp"   "pop"       "gdpPercap"
gapminder %>%
  select(ends_with("p")) %>%
  head()
## # A tibble: 6 × 3
##   lifeExp      pop gdpPercap
##     <dbl>    <int>     <dbl>
## 1    28.8  8425333      779.
## 2    30.3  9240934      821.
## 3    32.0 10267083      853.
## 4    34.0 11537966      836.
## 5    36.1 13079460      740.
## 6    38.4 14880372      786.

select(): Column selection

names(gapminder)
## [1] "country"   "continent" "year"      "lifeExp"   "pop"       "gdpPercap"
gapminder %>%
  select(contains("Per")) %>%
  head()
## # A tibble: 6 × 1
##   gdpPercap
##       <dbl>
## 1      779.
## 2      821.
## 3      853.
## 4      836.
## 5      740.
## 6      786.

select(): Column selection

mutate(): create new columns

gapminder %>%
  mutate(gdp = gdpPercap * pop) %>%
  head()
## # A tibble: 6 × 7
##   country     continent  year lifeExp      pop gdpPercap          gdp
##   <fct>       <fct>     <int>   <dbl>    <int>     <dbl>        <dbl>
## 1 Afghanistan Asia       1952    28.8  8425333      779.  6567086330.
## 2 Afghanistan Asia       1957    30.3  9240934      821.  7585448670.
## 3 Afghanistan Asia       1962    32.0 10267083      853.  8758855797.
## 4 Afghanistan Asia       1967    34.0 11537966      836.  9648014150.
## 5 Afghanistan Asia       1972    36.1 13079460      740.  9678553274.
## 6 Afghanistan Asia       1977    38.4 14880372      786. 11697659231.

mutate(): create new columns

gapminder %>%
  mutate(gdp = gdpPercap * pop,
         logGDP = log(gdp)) %>% 
  head()
## # A tibble: 6 × 8
##   country     continent  year lifeExp      pop gdpPercap          gdp logGDP
##   <fct>       <fct>     <int>   <dbl>    <int>     <dbl>        <dbl>  <dbl>
## 1 Afghanistan Asia       1952    28.8  8425333      779.  6567086330.   22.6
## 2 Afghanistan Asia       1957    30.3  9240934      821.  7585448670.   22.7
## 3 Afghanistan Asia       1962    32.0 10267083      853.  8758855797.   22.9
## 4 Afghanistan Asia       1967    34.0 11537966      836.  9648014150.   23.0
## 5 Afghanistan Asia       1972    36.1 13079460      740.  9678553274.   23.0
## 6 Afghanistan Asia       1977    38.4 14880372      786. 11697659231.   23.2

split-apply-combine

split-apply-combine

grouped_gap <- gapminder %>%
  group_by(continent)
head(grouped_gap, 4)
## # A tibble: 4 × 6
## # Groups:   continent [1]
##   country     continent  year lifeExp      pop gdpPercap
##   <fct>       <fct>     <int>   <dbl>    <int>     <dbl>
## 1 Afghanistan Asia       1952    28.8  8425333      779.
## 2 Afghanistan Asia       1957    30.3  9240934      821.
## 3 Afghanistan Asia       1962    32.0 10267083      853.
## 4 Afghanistan Asia       1967    34.0 11537966      836.

split-apply-combine

grouped_gap <- gapminder %>%
  group_by(continent)
tail(grouped_gap, 4)
## # A tibble: 4 × 6
## # Groups:   continent [1]
##   country  continent  year lifeExp      pop gdpPercap
##   <fct>    <fct>     <int>   <dbl>    <int>     <dbl>
## 1 Zimbabwe Africa     1992    60.4 10704340      693.
## 2 Zimbabwe Africa     1997    46.8 11404948      792.
## 3 Zimbabwe Africa     2002    40.0 11926563      672.
## 4 Zimbabwe Africa     2007    43.5 12311143      470.

split-apply-combine

ungrouped_gap <- ungroup(grouped_gap)
head(ungrouped_gap)
## # A tibble: 6 × 6
##   country     continent  year lifeExp      pop gdpPercap
##   <fct>       <fct>     <int>   <dbl>    <int>     <dbl>
## 1 Afghanistan Asia       1952    28.8  8425333      779.
## 2 Afghanistan Asia       1957    30.3  9240934      821.
## 3 Afghanistan Asia       1962    32.0 10267083      853.
## 4 Afghanistan Asia       1967    34.0 11537966      836.
## 5 Afghanistan Asia       1972    36.1 13079460      740.
## 6 Afghanistan Asia       1977    38.4 14880372      786.

split-apply-combine

gapminder %>%
  group_by(continent) %>%
  summarize(mean_lifeExp = mean(lifeExp, na.rm = TRUE),
            max_gdp = max(gdpPercap))
## # A tibble: 5 × 3
##   continent mean_lifeExp max_gdp
##   <fct>            <dbl>   <dbl>
## 1 Africa            48.9  21951.
## 2 Americas          64.7  42952.
## 3 Asia              60.1 113523.
## 4 Europe            71.9  49357.
## 5 Oceania           74.3  34435.

split-apply-combine

gapminder %>%
  group_by(continent) %>%
  summarize(summary_lifeExp = mean(lifeExp, na.rm = TRUE), median(lifeExp, na.rm = TRUE), sd(lifeExp, na.rm = TRUE))
## # A tibble: 5 × 4
##   continent summary_lifeExp `median(lifeExp, na.rm = TRUE)` sd(lifeExp, na.rm …¹
##   <fct>               <dbl>                           <dbl>                <dbl>
## 1 Africa               48.9                            47.8                 9.15
## 2 Americas             64.7                            67.0                 9.35
## 3 Asia                 60.1                            61.8                11.9 
## 4 Europe               71.9                            72.2                 5.43
## 5 Oceania              74.3                            73.7                 3.80
## # … with abbreviated variable name ¹​`sd(lifeExp, na.rm = TRUE)`

split-apply-combine

gapminder %>%
  group_by(continent) %>%
  summarize(mean_lifeExp = mean(lifeExp, na.rm = TRUE),
            max_gdp = max(gdpPercap)) %>%
  arrange(mean_lifeExp)
## # A tibble: 5 × 3
##   continent mean_lifeExp max_gdp
##   <fct>            <dbl>   <dbl>
## 1 Africa            48.9  21951.
## 2 Asia              60.1 113523.
## 3 Americas          64.7  42952.
## 4 Europe            71.9  49357.
## 5 Oceania           74.3  34435.

split-apply-combine

gapminder %>%
  group_by(continent) %>%
  summarize(mean_lifeExp = mean(lifeExp, na.rm = TRUE),
            max_gdp = max(gdpPercap)) %>%
  arrange(desc(mean_lifeExp))
## # A tibble: 5 × 3
##   continent mean_lifeExp max_gdp
##   <fct>            <dbl>   <dbl>
## 1 Oceania           74.3  34435.
## 2 Europe            71.9  49357.
## 3 Americas          64.7  42952.
## 4 Asia              60.1 113523.
## 5 Africa            48.9  21951.

pull(): extract column as vector

gapminder %>%
  select(lifeExp) %>%
  head(4)
## # A tibble: 4 × 1
##   lifeExp
##     <dbl>
## 1    28.8
## 2    30.3
## 3    32.0
## 4    34.0
gapminder %>%
  pull(lifeExp) %>%
  head(10)
##  [1] 28.801 30.332 31.997 34.020 36.088 38.438 39.854 40.822 41.674 41.763

pull(): extract column as vector

gapminder %>%
  select(continent) %>%
  head(4)
## # A tibble: 4 × 1
##   continent
##   <fct>    
## 1 Asia     
## 2 Asia     
## 3 Asia     
## 4 Asia
gapminder %>%
  select(continent) %>%
  head(20)
## # A tibble: 20 × 1
##    continent
##    <fct>    
##  1 Asia     
##  2 Asia     
##  3 Asia     
##  4 Asia     
##  5 Asia     
##  6 Asia     
##  7 Asia     
##  8 Asia     
##  9 Asia     
## 10 Asia     
## 11 Asia     
## 12 Asia     
## 13 Europe   
## 14 Europe   
## 15 Europe   
## 16 Europe   
## 17 Europe   
## 18 Europe   
## 19 Europe   
## 20 Europe

rename(): …renaming!

data(gapminder)
head(gapminder)
## # A tibble: 6 × 6
##   country     continent  year lifeExp      pop gdpPercap
##   <fct>       <fct>     <int>   <dbl>    <int>     <dbl>
## 1 Afghanistan Asia       1952    28.8  8425333      779.
## 2 Afghanistan Asia       1957    30.3  9240934      821.
## 3 Afghanistan Asia       1962    32.0 10267083      853.
## 4 Afghanistan Asia       1967    34.0 11537966      836.
## 5 Afghanistan Asia       1972    36.1 13079460      740.
## 6 Afghanistan Asia       1977    38.4 14880372      786.

rename(): …renaming!

gapminder %>%
  rename(life_exp = lifeExp)
## # A tibble: 1,704 × 6
##    country     continent  year life_exp      pop gdpPercap
##    <fct>       <fct>     <int>    <dbl>    <int>     <dbl>
##  1 Afghanistan Asia       1952     28.8  8425333      779.
##  2 Afghanistan Asia       1957     30.3  9240934      821.
##  3 Afghanistan Asia       1962     32.0 10267083      853.
##  4 Afghanistan Asia       1967     34.0 11537966      836.
##  5 Afghanistan Asia       1972     36.1 13079460      740.
##  6 Afghanistan Asia       1977     38.4 14880372      786.
##  7 Afghanistan Asia       1982     39.9 12881816      978.
##  8 Afghanistan Asia       1987     40.8 13867957      852.
##  9 Afghanistan Asia       1992     41.7 16317921      649.
## 10 Afghanistan Asia       1997     41.8 22227415      635.
## # … with 1,694 more rows
## # ℹ Use `print(n = ...)` to see more rows