[R-sig-Geo] Plot NUTS regions with color

Mathias Moser m@tmo@er @end|ng |rom wu@@c@@t
Thu Jun 24 08:33:26 CEST 2021


You need to create a frequency table from l and merge this to the shapefile.
Using sf/ggplot2 would also simplify things here:

> download.file("
> https://gisco-services.ec.europa.eu/distribution/v2/nuts/download/ref-nuts-2021-60m.geojson.zip
> ", "nuts.zip")
> unzip("nuts.zip",  exdir = tempdir())
> 
> library(dplyr)
> library(sf)
> EU_NUTS <- read_sf(paste0(tempdir(), "/NUTS_RG_60M_2021_4326_LEVL_3.geojson")
> 
> l <- c("AT223", "AT212", "AT212", "AT121")
> l_freq <- as.data.frame(table(l))
> 
> EU_NUTS <- left_join(EU_NUTS, l_freq, by = c("id" = "l"))
> 
> library(ggplot2)
> ggplot(filter(EU_NUTS, CNTR_CODE == "AT")) + geom_sf(aes(fill = Freq))

//m

On Wed, 2021-06-23 at 21:11 +0200, Phillips Rogfield wrote:
> Dear R-SIG-Geo ML,
> 
> I have downloaded the NUTS shapefiles from here: 
> https://ec.europa.eu/eurostat/web/gisco/geodata/reference-data/administrative-units-statistical-units/nuts
> 
> I can load them with the following code:
> 
>     library(rgdal)
>     shp_bdir <- [PATH TO SHAPE FILE]
>     layername <- "NUTS_RG_01M_2021_4326"
>     shp_folder <- file.path(shp_bdir, paste0(layername,".shp"))
>     EU_NUTS <- readOGR(dsn = shp_folder, layer = layername)
> 
> Then I can plot the regions with:
> 
>     plot(EU_NUTS)
> 
> Now I have a list of NUTS - 3 Level, for example:
> 
>     l <- c("AT223", "AT212", "AT212", "AT121")
> 
> I would like a plot where the NUTS regions are colored, and the more a 
> particular NUTS is present is the list, the darker its color.
> 
> For example "AT212" should be darker than "AT223", because the former is 
> present two times in the list.
> 
> How can I achieve that?
> 
> Thank you and best regards.
> 
> 
>         [[alternative HTML version deleted]]
> 
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo using r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo



More information about the R-sig-Geo mailing list