More Quick R Maps: Country View of WHO Confirmed Cases

who_world_swineflu_04282009.png

I realized it should be pretty easy to use the approach as the previous R map I generated to make a smaller scale map at a country level. In this example I’m setting up an initial non-plotted map with limits on the X and Y ranges I want to display. Next I assign colors to the observations of this subset map, plot these filled areas, then plot all boundaries.

I’m not really happy with this map because (1) I don’t really like just throwing out maps with just geographic coordinates, and (2) using area coloring can be a bit misleading about the magnitude and dispersal of the data presented: in this case there are really small clusters of reported cases, not country wide. I think this map might be a good index map to get an overview of the spread and number of cases, but would need to be backed by more detailed maps that do not generalize the location of outbreaks as much.

who_world_swineflu_04282009.png

Here’s the source:

# load required libraries
require(maps)
require(RColorBrewer)

# Create a dataframe with the reported observations
loc <- c('USA', 'Mexico', 'Canada', 'Spain')
cases <- c(40, 26, 6, 1)
flu <- data.frame(loc,cases)

# Setup the coordinate system
m <- map('world',plot=F, xlim=c(-180,5),ylim=c(10,90), fill=T)

# Match up our observations
stm <- match.map(m, flu$loc)

# Rank the cases and assign colors using the RColorBrewer YlOrRd palette
flu$rank <- rank(flu$cases, ties='min')
pal <- brewer.pal(max(flu$rank),'YlOrRd')
color <- pal[flu$rank]
flu.color <- color[stm]

# Do the drawing
map(m,col=flu.color,fill=T, lty=0,boundary=F,interior=F) # fill regions
map('world',interior=T,add=T,col='grey30') # plot boundaries
map.axes()
grid(col='grey50')
title('WHO Confirmed Cases of Swine Flu by Country (28 April 2009)')
legend('bottomleft', legend=paste(flu$loc,flu$cases),
	fill=color, bg='white', horiz=T, cex=0.75,
	title=paste('Jason B. Smith | 28 April 2009 | Source: CNN.com'))

One thought on “More Quick R Maps: Country View of WHO Confirmed Cases”

  1. Thank’s you helped me a lot.

    PS: Your code has some HTML-Code which shouldn’t be there. <- instead of < for example.

Leave a Reply