Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Colour polygons of a map in R?

Tags:

r

maps

raster

I have used Raster package to upload the map of Spain by provinces (level 2) and I'd like to fill them with colours according to theincome per capita. Here there's the file with the income per share and the number assigned to each province. Notice that ID_2 is the number assigned by the package Raster, and the variable PROV is the official number assigned by the Spanish Government.

library(raster)
esp<-getData('GADM', country="ESP", level=2)
espPols <- unionSpatialPolygons(esp, esp$ID_2)
renta <- read.table("renta.csv",sep = ";", header=TRUE)
espMapRenta <- SpatialPolygonsDataFrame(espPols, renta)
plot(espMapRenta)

The first problem I encounter is that there are some provinces repeated in the package, and the second one is that I don't know how to fill each province in a gradient colour by the level of income.

Thank you very much for your help!! PS. The link to the income per capita data is here: https://www.dropbox.com/s/si6zpv7p2nap9zg/renta.csv?dl=0

like image 696
adrian1121 Avatar asked Dec 05 '25 09:12

adrian1121


1 Answers

Are you looking for something like that?

library(sp)
spplot(espMapRenta, zcol="Renta.per.Capita")

enter image description here

like image 138
MLavoie Avatar answered Dec 07 '25 16:12

MLavoie



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!