Adam Dragula
Adam Dragula

Reputation: 51

Mapping Europe with tmap package

I would like to map some raster data using tmap package. My geographical extent is Europe and R cannot find the map of Europe altough I got the latest version of R and all packages required. I am trying this:

 library(tmap)
 data(Europe)
 tm_shape(Europe) + tm_fill()

And it writes this

 Error in as.list.environment(environment()) : object 'Europe' not found

I found this way to do it on almost every website, havent a clue why it doesnt work. Thanks for your help!

Upvotes: 0

Views: 1301

Answers (3)

Tiziano
Tiziano

Reputation: 321

I use giscoR pacage and, for the boundaries, I pass to tm_shape() function the output of the gisco_get_nuts() function from the giscoR package.

Usually, I define and save in a geojson file the map's BBOX by selecting my area of interest visually using the https://geojson.io tool

A code template may be the following

library(sf)
library(geojsonsf)
library(giscoR)
library(tmap)
library(tmaptools)

map.bbox <- st_bbox(geojson_sf(geojson = "_data/bbox_europa_continental.geojson"))
country.ISO3_CODE <- gisco_countrycode %>% filter(continent == "Europe") %>% select(ISO3_CODE) %>% unlist(use.names = F)

gisco_get_nuts(country = country.ISO3_CODE, 
               spatialtype = "RG", nuts_level = 0) %>% 
  tm_shape(bbox = map.bbox) + tm_polygons() + tm_borders()

enter image description here

Notes: to date it seems that the giscoR package miss Bosnia and Kosovo boundaries

Upvotes: 0

kraggle
kraggle

Reputation: 347

Maybe you can find a combo that works. This is just a sample of subsets.

library(tmap)

tm_shape(countries_spdf[countries_spdf@data$subregion == "Western Europe", ]) +
tm_borders()

tm_shape(countries_spdf[countries_spdf@data$subregion == "Eastern Europe", ]) +
tm_borders()

tm_shape(countries_spdf[countries_spdf@data$region == "Europe", ]) +
tm_borders()

Upvotes: 0

Jindra Lacko
Jindra Lacko

Reputation: 8719

The Europe dataset has been dropped from {tmap} since release 2. But it used to live there, and you can still find it in many older blogposts and even SO answers (including mine I am afraid).

You might get it to work if you downgrade {tmap} to version 1.11-2 or lower.

Or you might build Europe shape from other packages, there are a plenty. For a quick & dirty visualization you may consider {rnaturalearth}, for something more fancy consider {giscoR}, which is interfaced to Eurostat.

world <- rnaturalearth::countries110
europe <- world[world$region_un=="Europe"&world$name!='Russia',]

library(tmap)

tm_shape(europe) + tm_fill()

enter image description here

Upvotes: 3

Related Questions