Session Ready
Exercise

Map projections

You saw in the last video how to use the mapplot() function in latticeExtra to display numeric data associated with geographical regions, such as states or counties, by converting the numeric data to colors.

Since the earth is three dimensional but the plot is two dimensional, a projection is required to reduce the number of dimensions. The list of available projections is given in the Details section of the mapproject() help page. The example you saw in the video used the Mercator projection. Here is an example using a polyconic projection.

usa_map

Map plots are drawn in two stages. First, a map object is created using the map() function from the maps package with plot = FALSE.

the_map <- map("a_map_dataset", plot = FALSE, projection = "some_projection")

Second, mapplot() is called with a formula, a data frame, and a map.

mapplot(region ~ value, data, map = the_map)

In this exercise, your task is to create another choropleth map of the cancer death-rates data using a different projection.

Instructions
100 XP

The USCancerRates dataset has been pre-loaded.

  • Load the required packages maps and latticeExtra.

  • Create a "map" object representing US counties using the map() function.

    • Set the fill argument to TRUE to have shaded regions.
    • Set the projection argument to the string "sinusoidal". This is an equal-area projection with equally spaced parallels.
  • Create a choropleth map of county-wise death rates for both males and females. The formula for mapplot() should have the structure region ~ value1 + value2, where

    • region should represent the county names, which in this case should be the row names of the USCancerRates dataset, and
    • value1 and value2 are the associated numeric data to be plotted in separate panels, which in this case should be log10 transformed death rates for males and females.
    • The map argument should be the "map" object created in the previous step.