“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:
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
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:
##  "afghanistan" "aland" "albania" "algeria" ##  "american samoa" "andorra"
The map lists the country as “japan” (all lowercase). Now let's see how the map names the prefectures of 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:
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
df_japan_census$value = df_japan_census$pop_2010
Now that our data is prepared for choroplethr, we can view the data with the function
library(choroplethr) ?admin1_choropleth admin1_choropleth(country.name = "japan", df = df_japan_census, title = "2010 Japan Population Estimates", legend = "Population", num_colors = 1)
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)