Keith Newman

Keith Newman

R Code

It's quite often that I find myself writing code to use in the open-source statistical software, R. Half the time, I never actually needed the code for anything - I have either written the code for fun or I'm writing the code to help a fellow student with their own work.

I would normally display code on Poisson Processes and Simple Random Walks in this section, but these have been temporarily removed for the next few weeks. If you really need to see them, send me an email and I may send you a link.

Plotting World and Country Maps

Map of British Isles produced using R

In my project, I am using some real data about annual daily-maximum rainfall at a number of sites around the country. I have the longitude and latitudes of each site, so I wanted to plot where each of the sites are on a map. Fortunately I didn't have to draw a map of Great Britain myself as packages already exist which can plot every country of the World for you.

Here I explain how you can plot a map of the World or any combination of countries using the functions and data readily available to use. I do a specific example for plotting the British Isles and show how to highlight a location on the map you've just plotted.

View the Map Plotting code here.

Plotting Country Maps using GADM data

Map of Great Britain shaded in regionally

Ever since I wrote my previous guide to plotting maps in R, I have received the occasional email asking for further help in plotting some maps. What I've found is that the GADM website provides some very useful datasets for non-commercial purposes.

The method is slightly different when using GADM data—it actually uses the plot() command from the 'sp' package rather than the map() function—so this provides a nice opportunity for a follow-up on the previous walkthrough. This guide also includes an example of colouring different regions according to a (simulated) numerical value.

View the Map Plotting (using GADM data) code here.