0

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!

3 Answers3

3

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

Jindra Lacko
  • 7,814
  • 3
  • 22
  • 44
0

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()
kraggle
  • 196
  • 2
  • 9
0

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

Tiziano
  • 271
  • 1
  • 5
  • 9