Creating Administrative Level 1 Maps

“Administrative Level 1” is the generic term for the largest subnational administrative unit of a country. This unit has different names depending on the country. For example, in the USA Admin 1 units are called “states”, but in Japan they are called “prefectures”. choroplethr ships with an Admin 1 map of all countries of the world, and supports creating choropleths of these maps. To learn more about the map type the following:

library(choroplethrAdmin1)
?admin1.map

This vignette walks thru an example of using choroplethr to create an Admin 1 choropleth of Japan. The data we will use is 2010 population estimates from the Japanese Census Bureau:

library(choroplethr)
?df_japan_census
data(df_japan_census)
head(df_japan_census)
##    region pop_2010 percent_pop_change_2005_2010 pop_density_km2_2010
## 23  aichi  7411000                          2.2               1434.8
## 5   akita  1086000                         -5.2                 93.3
## 2  aomori  1373000                         -4.4                142.4
## 12  chiba  6216000                          2.6               1205.5
## 38  ehime  1431000                         -2.5                252.1
## 18  fukui   806000                         -1.9                192.4

Step 1: Verify that names match

In order to create a choropleth of our data we first need to understand how names are treated both in the map and in our data. If the names are not the same in both places we will need to make adjustments. (For example if the map says “Tōkyō” but our data says “Tokyo” the map will not render correctly).

First let's see how the map spells the country:

head(get_admin1_countries())
## [1] "afghanistan"    "aland"          "albania"        "algeria"       
## [5] "american samoa" "andorra"

The map lists the country as “japan” (all lowercase). Now let's see how the map names the prefectures of Japan:

head(get_admin1_regions("japan"))
##      country region
## 1618   japan  aichi
## 1619   japan  akita
## 1620   japan aomori
## 1621   japan  chiba
## 1622   japan  ehime
## 1623   japan  fukui

They appear in all lower-case without a trailing “-ken”. Note that this is exactly the same convention used in our data. So the names match and we can proceed to the next step.

Note that if you would like to create an Admin 1 map of Japan then type this:

admin1_map("japan")

plot of chunk unnamed-chunk-5

Step 2: Prepare our data

choroplethr requires our data to be in a specific format: a data.frame that contains one column named “region” and one column named “value”. df_japan_census has a region column and several columns of data. But none of them are called value. For the purposes of this example, let's copy the pop_2010 column to the value column.

df_japan_census$value = df_japan_census$pop_2010

Step 3: Explore our data

Now that our data is prepared for choroplethr, we can view the data with the function admin1_choropleth:

library(choroplethr)
?admin1_choropleth
admin1_choropleth(country.name = "japan", 
                  df           = df_japan_census, 
                  title        = "2010 Japan Population Estimates", 
                  legend       = "Population", 
                  num_colors   = 1)

plot of chunk unnamed-chunk-7

As with all choropleth functions, you can also zoom in to specific regions and change the scale. Here is an example of zooming in on the Kansai region of Japan with a continuous scale:

kansai = c("mie", "nara", "wakayama", "kyoto", "osaka", "hyogo", "shiga")
admin1_choropleth(country.name = "japan", 
                  df           = df_japan_census, 
                  title        = "2010 Japan Population Estimates - Kansai Region", 
                  legend       = "Population", 
                  num_colors   = 1, 
                  zoom         = kansai)

plot of chunk unnamed-chunk-8