Now we have everything to create our first thematic map. Let's pass the val
vector to the previously used map
function (or plot
it using the us
object), specify a plot title, add a blue point for Houston, and then create a legend, which shows the quantiles of the overall number of cancelled flights as a reference:
> map("state", col = rgb(1, 0, 0, sqrt(val/max(val))), fill = TRUE) > title('Number of cancelled flights from Houston to US states') > points(h$lon, h$lat, col = 'blue', pch = 13) > legend('bottomright', legend = round(quantile(val)), + fill = rgb(1, 0, 0, sqrt(quantile(val)/max(val))), box.col = NA)
Please note that, instead of a linear scale, we have decided to compute the square root of the relative values to define the intensity of the fill color, so that we can visually highlight the differences between the states. This was necessary as most flight cancellations happened in Texas (748
), and there were no more than 150 cancelled flights in any other state (with the average being around 45).
Another, probably easier, way to generate country-level thematic maps, especially choropleth maps, is to load the rworldmap
package made by Andy South, and rely on the convenient mapCountryData
function.
3.142.42.176