R Markdown

library(tmaptools)
library(tmap)
library(cartogram)
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
    data(World, metro)
    World %>% filter(continent=="Europe") %>% filter(name != "Russia") %>% filter(name != "Luxembourg") ->Europe
    Europe$economy<-droplevels(Europe$economy)
    w2<-cartogram(Europe,weight="pop_est")
## 
## Please use cartogram_cont() instead of cartogram().
## Mean size error for iteration 1: 2.07700353114722
## Mean size error for iteration 2: 1.74405718075317
## Mean size error for iteration 3: 1.51849372610728
## Mean size error for iteration 4: 1.36868910625817
## Mean size error for iteration 5: 1.27108856145315
## Mean size error for iteration 6: 1.20384004285519
## Mean size error for iteration 7: 1.1650151725019
## Mean size error for iteration 8: 1.13849442779184
## Mean size error for iteration 9: 1.11892892223971
## Mean size error for iteration 10: 1.10428490240881
## Mean size error for iteration 11: 1.09280525999413
## Mean size error for iteration 12: 1.08223106224238
## Mean size error for iteration 13: 1.07234826848279
## Mean size error for iteration 14: 1.06469804636962
## Mean size error for iteration 15: 1.05790532622249
    World$color <- map_coloring(World, palette="Pastel2")
    qtm(World, fill = "color")

    # map_coloring used indirectly: qtm(World, fill = "MAP_COLORS")

    data(NLD_prov, NLD_muni)
    tm_shape(NLD_prov) +
        tm_fill("name", legend.show = FALSE) +
    tm_shape(NLD_muni) +
        tm_polygons("MAP_COLORS", palette="Greys", alpha = .25) +
    tm_shape(NLD_prov) +
        tm_borders(lwd=2) +
        tm_text("name", shadow=TRUE) +
    tm_format("NLD", title="Dutch provinces and\nmunicipalities", bg.color="white") 

data(World, rivers, metro)

# just the map
qtm(World)

# choropleth
qtm(World, fill = "economy", format = "World", style = "col_blind")

# choropleth with more specifications
qtm(World, fill="HPI", fill.n = 9, fill.palette = "div",
    fill.title = "Happy Planet Index", fill.id = "name", 
    style = "classic", format = "World")

# this map can also be created with the main plotting method,
# which is recommended in this case.
## Not run: 
w2$gdp<-log10(w2$gdp_cap_est)
tm_shape(w2) +
    tm_polygons("economy",
        title = "GDP", id = "name") +
tm_style("classic") +
tm_format("World") + tm_compass()