Quantcast
Channel: R-bloggers
Viewing all articles
Browse latest Browse all 12091

Mapping to a ‘t'(map)

$
0
0

(This article was first published on HighlandR, and kindly contributed to R-bloggers)

tmap <- Easy & Interactive -

More maps of the Highlands?

Yep, same as last time, but no need to install dev versions of anything, we can get awesome maps courtesy of the tmap package.

Get the shapefile from the last post

library(tmap)library(tmaptools)library(viridis)scot<-read_shape("SG_SIMD_2016.shp",as.sf=TRUE)highland<-(scot[scot$LAName=="Highland",])#replicate plot from previous blog post:quint<-tm_shape(highland)+tm_fill(col="Quintile",palette=viridis(n=5,direction=-1,option="C"),fill.title="Quintile",title="SIMD 2016 - Highland Council Area by Quintile")quint# plotttm()#switch between static and interactive - this will use interactivequint# or use last_map()# in R Studio you will find leaflet map in your Viewer tabttm()# return to plotting

The results:

tmap-Highland-SIMD-Quintile.png

One really nice thing is that because the polygons don’t have outlines, the DataZones that are really densely packed still render nicely – so no ‘missing’ areas.

A static image of the leaflet map:

leaflet-snapshot.png

Here I take the rank for all the Highland data zones, and the overall SIMD rank, and create a small multiple

small_mult<-tm_shape(highland)+tm_fill(col=c("IncRank","EmpRank","HlthRank","EduRank","GAccRank","CrimeRank","HouseRank","Rank"),palette=viridis(n=5,direction=-1,option="C"),title=c("Income Rank","Employment Rank","Health Rank","Education Rank","General Access Rank","Crime Rank","Housing Rank","Overall Rank"))small_mult

2017-08-31-tmap-Highland-SIMD-All-Domains-Ranked.png

Let’s take a look at Scotland as a whole, as I assume everyone’s pretty bored of the Highlands by now:

#try a map of scotlandscotplot<-tm_shape(scot)+tm_fill(col="Rank",palette=viridis(n=5,direction=-1,option="C"),fill.title="Overall Rank",title="Overall-Rank")scotplot# bit of a monster

2017-08-31ScotSIMD.png

With the interactive plot, we can really appreciate the density of these datazones in the Central belt.

2017-08-31-scotland-leaflet.PNG

Here, I’ve zoomed in a bit on the region around Glasgow, and then zoomed in some more:

2017-08-31-scotland-leaflet-zoom-in1.PNG

2017-08-31-scotland-leaflet-zoom.PNG

I couldn’t figure out how to host the leaflet map within the page (Jekyll / Github / Leaflet experts please feel free to educate me on that 🙂 ) but, given the size of the file, I very much doubt I could have uploaded it to Github anyway.

Thanks to Roger Bivand (@RogerBivand) for getting in touch and pointing me towards the tmap package! It’s really good fun and an easy way to get interactive maps up and running.

var vglnk = { key: '949efb41171ac6ec1bf7f206d57e90b8' }; (function(d, t) {var s = d.createElement(t); s.type = 'text/javascript'; s.async = true;s.src = '//cdn.viglink.com/api/vglnk.js';var r = d.getElementsByTagName(t)[0]; r.parentNode.insertBefore(s, r); }(document, 'script'));

To leave a comment for the author, please follow the link and comment on their blog: HighlandR.

R-bloggers.com offers daily e-mail updates about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...


Viewing all articles
Browse latest Browse all 12091

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>