Introduction

library(readr)
library(rnaturalearth)
library(sf)
## Linking to GEOS 3.5.1, GDAL 2.1.2, PROJ 4.9.3
library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
library(tidyr)
library(mapview)
countries<-st_as_sf(rnaturalearth::countries110)
pop<-read.csv("population.csv")
countries %>% select("iso_a3") %>% rename("Code" = "iso_a3") %>% inner_join(pop) ->pop
## Joining, by = "Code"
## Warning: Column `Code` joining character vector and factor, coercing into
## character vector
pop %>% filter(Year==2000) -> pop_2000
library(cartogram)
st_crs(pop_2000)<- 3395
## Warning: st_crs<- : replacing crs does not reproject data; use st_transform
## for that
pop_2000 %>% filter(Population>0) %>% cartogram_cont(weight="Population") -> carto
## Mean size error for iteration 1: 3.76858113282894
## Mean size error for iteration 2: 2.9382849749674
## Mean size error for iteration 3: 2.80475613201574
## Mean size error for iteration 4: 2.58998025576398
## Mean size error for iteration 5: 2.48081528467337
## Mean size error for iteration 6: 2.44544357664784
## Mean size error for iteration 7: 2.77925553536001
## Mean size error for iteration 8: 65.733087560816
## Mean size error for iteration 9: 15.9903150041887
## Mean size error for iteration 10: 4.1633167672898
## Mean size error for iteration 11: 2.27355392244199
## Mean size error for iteration 12: 1.83428258154999
## Mean size error for iteration 13: 1.72742793739142
## Mean size error for iteration 14: 1.74468172890666
## Mean size error for iteration 15: 1.82402527070929
library(tmap)
qtm(carto)