In this recipe, we will learn how to plot data on regional maps within individual countries rather than the whole world map. We will look at examples based on the United States and European countries.
Just as with the previous recipe, we will make use of the maps
package to draw the map and the RColorBrewer
package to choose color schemes. So, let's make sure that they are loaded:
library(maps) library(RColorBrewer)
We will use the inbuilt USArrests
example dataset, which contains crime statistics, in arrests per 100,000 residents for assault, murder, and rape in each of the 50 US states in 1973.
Let's plot the arrests rate for murders in US states in 1973. The default graphics device size might not be big enough for the map; thus, if you get an error about figure margins, enlarge the graphics device:
x<-map("state",plot=FALSE) for(i in 1:length(rownames(USArrests))) { for(j in 1:length(x$names)) { if(grepl(rownames...