Map of World Rally Championship (WRC) Driver Wins by Nationality

More motor racing and map making. This time it's the World Rally Championship (WRC). I found this Wikipedia table of WRC driver wins by nationality and thought I'd make a map similar to the ones I made for F1 Grand Prix wins and US soccer players in foreign leagues. As much as I like those maps, I realized that gradient shading is insufficiently communicative when it comes to relatively small datasets whose numeric values are so far apart that calling them "continuous" is in practice a misnomer. This was exemplified by my first attempt at making this WRC map, the dataset for which includes 17 rows with values spanning 1 to 184. I decided instead to figure out how to plot the map using specific colors for each number of WRC wins in the dataset. Here is the result:

(click to enlarge)

The first modification to my R code was to change the class of worldplot$Wins from numeric to factor like so:

> worldplot$Wins<-as.factor(worldplot$Wins)

Doing so also necessitated changing scale_fill_gradientn in ggplot to scale_fill_manual given that this column was now considered by ggplot to be discrete rather than continuous data.

Running this new code created a map with a legend key that had the numbers of wins in ascending order. I found this order preferable to the legend key created when I converted worldplot$Wins from numeric to character instead, which was arranged by ascending order of the first digit in each number rather than numeric value, so all numbers starting with a "1" (1, 17, 177, 184) were grouped together and so on. Still, I wanted the legend key in descending order rather than ascending order, a change that I effected with this code within the ggplot grammar:

+   guides(fill = guide_legend(reverse = TRUE))+

Lastly, I played around with the colors quite a bit. Once again, I took advantage of the colorRampPalette function in the RColorBrewer package to expand the sizes of the color palettes available. Once I created my vector of 11 colors using this function, I then replaced individual components of that vector with other colors based on the appearance on the map. By doing this, I hoped to increase the distinction between the different colors, and I think I succeeded.

The steps of this process were as follows. After creating a variable representing the vector of colors made with colorRampPalette, I called that variable in the console in order to see its composition. I then made a new variable with this same vector so I could experiment safely. Here is what that step looks like:

> ctest<-c("#8DD3C7", "#FDFDB3", "#C0B7D5", "#F28378", "#8BB1C8", "#F4B862", "#BDDB7A", "#F6CEE3", "#D3C8D3", "#BF96BE", "#D7EBB1")

I then changed the components of this vector that I thought were hard to distinguish on the map. Here is the final vector of colors that I used for the map above:

> ctest<-c("#8DD3C7", "#FDFDB3", "red", "darkorchid4", "#8BB1C8", "#F4B862", "blue", "#F6CEE3", "green", "#BF96BE", "#D7EBB1")

For making maps using datasets of this size and composition, I think that this as.factor approach coupled with manual tweaking of the colors is definitely the way to go.

Comments

Popular Posts