I have been trying to build a Choropleth / Bubble map of UK for my own shiny dashboard project.
My dashboard is a student information management system and the map is supposed to show students come from which regions (zip codes or cities is also fine). Unfortunately, most packages, such as plotly and ggmap, only cover information about states of USA.
So, could someone please tell me how to create a map for UK? Here is an example of what I am trying to accomplish: Choropleth Map for UK
This is a step-by-step implementation of what I meant by my comment. I did not use the External Post that I mentioned, but it looks like another reference that does something like what I do to make a map.
Like @FR. said in his answer, GADM is a good place to get the needed map data - a shapefile.
If you do not already have them, install the packages
sp
,rgeos
andmaptools
.Now some fairly simple R code
There are actually three shapefiles in the zip: adm0, adm1, and adm2. Try all three to see which has the level of detail that you want. Also, note that there are a bunch of files with essentially the same names, but with different extensions. You want to load the .shp file.
You might experiment with the three shapefiles provided adm0, adm1 and adm2 (they have different levels of detail). You might also experiment with cropping off some of the distant outlying islands to get a good view of the main island.
Now you have the data in an R object, you can get at what is inside.
names(UK_adm2)
will show you some internal data. You can get a list of the counties by typingUK_adm2$NAME_2
. Let's highlight Bedfordshire.plot(UK_adm2[3,], col="#FF444488", add=TRUE)
You just saw that you can color individual counties. What you have to do is figure out how you want to color each of them. That will mean mapping whatever quantity you want to display to a color scheme. Take a look at
colorRampPalette
. Then you will want something like this:except that where I wrote
col=rainbow(12, alpha=0.6)
you will need to substitute a color scheme that is meaningful.