aaumaitre / maps_Spain

plotting tutorial for maps of Spain with ggplot2
55 stars 5 forks source link

Comments #1

Open rsbivand opened 4 years ago

rsbivand commented 4 years ago

A couple of comments. Do you know Displaying Time Series, Spatial, and Space-Time Data with R by Oscar Perpiñán Lamigueiro (https://www.crcpress.com/Displaying-Time-Series-Spatial-and-Space-Time-Data-with-R/Perpinan-Lamigueiro/p/book/9781138089983)? Might it have helped?

Do you know of ggplot2::geom_sf(); it handles "sf" objects natively? Using tidy etc. mangles the spatial objects, missing holes in polygons, so please do not promote it; not fit for purpose (Hadley Wickham's useR! plenary talk in 2016).

The colour reversal is all down to ggplot, which reads palettes the other way from everything else (you'd need a direction argument to sort out a twitter comment).

classInt provides all you need to choose thematic mapping class intervals, including user-defined fixed breaks. It is used internally by sf, tmap and cartography. Using tmap, your maps are close to one-liners; inset maps are presented in Lovelace et al. (2019) ch. 8 (https://www.crcpress.com/Geocomputation-with-R/Lovelace-Nowosad-Muenchow/p/book/9781138304512), also(https://geocompr.robinlovelace.net/). @robinlovelace, @Nowosad - could you advise - original reference here https://twitter.com/ariamsita/status/1188548779772907526? I couldn't find your data, so chose Renta media por persona.

library(sf)
med_inc <- read.csv("Renta media por persona.csv", stringsAsFactors=FALSE)
cas <- st_read("Comunidades_Autonomas_ETRS89_30N.shp", stringsAsFactors=FALSE)
med_inc$Codigo <- substring(med_inc$X, 1, 2)
cas1 <- merge(cas, med_inc, by="Codigo")
library(wesanderson)
pal <- wes_palette("Zissou1", 5, type = "discrete")
plot(cas1[-5,"X2017"], nbreaks=5, breaks="quantile", pal=pal) # dropping the Canaries for now.
library(tmap)
tm_shape(cas1[-5,]) + tm_fill("X2017", n=5, style="quantile", pal=pal, title="Income per capita €")

Renta media por persona.zip - my CSV data file. Shapefile from https://www.arcgis.com/home/item.html?id=5f689357238847bc823a2fb164544a77 as in the main document.

Also note that this ESRI-source file is UTM zone 30 (projected), but the only Municipios_IGN file I saw was in geographical coordinates - you did not show how to project/transform the object.

And yes, most things can be done without tidyverse, unless it is essential.

Nowosad commented 4 years ago

@rsbivand @aaumaitre - I prepared some code for two alternative approaches to create an inset map in R at https://github.com/Nowosad/spain-map-layout.