Map of All-Time Formula 1 Grand Prix Wins by Country (Drivers)

Time for a break from association football datasets. This project instead focused on the all-time Formula 1 Grand Prix wins based on nationality of the winning drivers. I found the data for the project at Wikipedia, and updated the totals to include the winner of today's Bahrain Grand Prix. After some minor modifications of the dataset (primarily matching the country names to those in the world dataset), I apply virtually the same code that I used for my American soccer players abroad map. Here is the result:

(click to enlarge)

I tweaked the aesthetics of the map by changing the country borders to gray and the countries without a Formula 1 GP winner (i.e., the NA values in the merged and plotted dataset) to cadetblue4. This allowed the region with the darkest shading (the United Kingdom) to stand out more from the background than if I left it as dark gray.

As has become the norm, this project proved more difficult than I imagined. I thought I would produce a quick map in time for the start of today's grand prix using the code that I used in previous projects. However this time I got the following error message along with a map without shading:
Warning messages:
1: In grid.Call(L_textBounds, as.graphicsAnnot(x$label), x$x, x$y,  :
  font family not found in Windows font database
2: In grid.Call(L_textBounds, as.graphicsAnnot(x$label), x$x, x$y,  :
  font family not found in Windows font database
I searched and searched the interwebs for a solution that applied to my situation, but I found none. To be sure, others have encountered this error message, but it seemed that it was usually in conjunction with an attempt to use a novel font. I had not done anything to the fonts. This left me very frustrated.

I eventually discovered the solution to the problem. I first determined that there was some formatting issues with the dataset I pulled from Wikipedia. Specifically, the names of the countries had some spaces before and/or after the words in my .csv file. Once I re-typed the names without the spaces (fortunately there weren't too many countries on the list), the shading appeared on the map. However, I was still getting the error message, and after examining the structure (str) of both my data frame and the world data frame (which I swear I did before to no avail), I discovered that the countries in my data frame were factors whereas the countries in the world data set were characters. I changed the countries in my data set to characters, re-ran the code, and guess what? No more error messages! I hope that this helps other R coders who encounter this same error message.


Popular Posts