# install.packages("mosaic") 
library(mosaic)
## Registered S3 method overwritten by 'mosaic':
##   method                           from   
##   fortify.SpatialPolygonsDataFrame ggplot2
## 
## The 'mosaic' package masks several functions from core packages in order to add 
## additional features.  The original behavior of these functions should not be affected by this.
## 
## Attaching package: 'mosaic'
## The following objects are masked from 'package:dplyr':
## 
##     count, do, tally
## The following object is masked from 'package:Matrix':
## 
##     mean
## The following object is masked from 'package:ggplot2':
## 
##     stat
## The following objects are masked from 'package:stats':
## 
##     binom.test, cor, cor.test, cov, fivenum, IQR, median, prop.test,
##     quantile, sd, t.test, var
## The following objects are masked from 'package:base':
## 
##     max, mean, min, prod, range, sample, sum
head(CIAdata())
##             Category                  Field   Name Code                 Unit
## 1          Geography                   Area   area 2147                sq km
## 2 People and Society             Population    pop 2119               people
## 3 People and Society Population growth rate growth 2002                    %
## 4 People and Society             Birth rate  birth 2054   births/1000 people
## 5 People and Society             Death rate  death 2066   deaths/1000 people
## 6 People and Society     Net migration rate   migr 2112 migrants/1000 people
# install.packages("openintro")
library(openintro)
## Loading required package: airports
## Loading required package: cherryblossom
## Loading required package: usdata
## 
## Attaching package: 'openintro'
## The following object is masked from 'package:mosaic':
## 
##     dotPlot
## The following objects are masked from 'package:lattice':
## 
##     ethanol, lsegments
head(cia_factbook)
## # A tibble: 6 × 11
##   country        area birth_rate death_rate infant_mortality_rate internet_users
##   <fct>         <dbl>      <dbl>      <dbl>                 <dbl>          <dbl>
## 1 Russia       1.71e7       11.9      13.8                   7.08       40853000
## 2 Canada       9.98e6       10.3       8.31                  4.71       26960000
## 3 United Stat… 9.83e6       13.4       8.15                  6.17      245000000
## 4 China        9.60e6       12.2       7.44                 14.8       389000000
## 5 Brazil       8.51e6       14.7       6.54                 19.2        75982000
## 6 Australia    7.74e6       12.2       7.07                  4.43       15810000
## # ℹ 5 more variables: life_exp_at_birth <dbl>, maternal_mortality_rate <int>,
## #   net_migration_rate <dbl>, population <int>, population_growth_rate <dbl>

get summary stats of population growth rate

summary(cia_factbook$population_growth_rate)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max.    NA's 
##  -9.730   0.260   1.020   1.101   1.920   9.370      26

View countries with the highest and lowest population growth rates

library(dplyr)
cia_factbook %>% 
  select(country, population_growth_rate) %>%
  arrange(desc(population_growth_rate)) %>%
  head() 
## # A tibble: 6 × 2
##   country     population_growth_rate
##   <fct>                        <dbl>
## 1 Lebanon                       9.37
## 2 Zimbabwe                      4.36
## 3 South Sudan                   4.12
## 4 Jordan                        3.86
## 5 Qatar                         3.58
## 6 Malawi                        3.33
cia_factbook %>% 
  select(country, population_growth_rate) %>% 
  arrange(population_growth_rate) %>% 
  head()
## # A tibble: 6 × 2
##   country                   population_growth_rate
##   <fct>                                      <dbl>
## 1 Syria                                      -9.73
## 2 Cook Islands                               -3   
## 3 Moldova                                    -1.02
## 4 Saint Pierre and Miquelon                  -1.02
## 5 Bulgaria                                   -0.83
## 6 Estonia                                    -0.68