Home > Software engineering >  R tmap print Italy
R tmap print Italy

Time:05-03

I want to draw a map. The country that I need to pront is Italy and I use this code:

library(sf)
library(raster)
library(dplyr)
library(spData)
library(spDataLarge)
library(tmap) # for static and interactive maps
library(leaflet) # for interactive maps
library(ggplot2) # tidyverse data visualization package

map = tm_shape(it)   tm_fill()   tm_borders()

print(map)

If I write nz or world works but other contry not, why? How can I print Italy? Exist another code? I don't find anything that works.

CodePudding user response:

You can download, read, and plot a regional map of Italy in tmap like this:

library(tmap)
library(sf)

url <- "https://geodata.ucdavis.edu/gadm/gadm4.0/shp/gadm40_ITA_shp.zip"

download.file(url, "../italia.zip")
unzip("../italia.zip", exdir = "italia")
It <- st_read("../italia/gadm40_ITA_2.shp")
map <- tm_shape(It)   tm_fill("NAME_1")   tm_borders()

print(map)

enter image description here

  • Related