Today I am happy to announce that my newest R package, choroplethrCaCensusTract, is now available on github. The package’s title is a combination of three words:
The package helps you visualize data that is aggregated at the level of census tracts in California. It also helps you to work with demographic data from the US Census Bureau that is aggregated at this level.
# install.packages("devtools") library(devtools) install_github("[email protected]", "arilamstein") library(choroplethrCaCensusTract) data(df_pop_ca_tract) ?df_pop_ca_tract ?ca_tract_choropleth ca_tract_choropleth(df_pop_ca_tract, title = "2012 Population Estimates\n California Census Tracts", legend = "Population") + coord_map()
Note that you can add any projection to this map by using ggplot2’s coord_map() function. Simply add “+ coord_map()” to the above function call.
Because census tracts normally have less than 8,000 people, it is hard to see the tracts in urban areas on a state-wide map. We can zoom in on individual counties by using the county_zoom parameter. county_zoom takes a vector of County FIPS Codes.
# 6075 is the FIPS code for San Francisco County ca_tract_choropleth(df_pop_ca_tract, title = "2012 Population Estimates\n San Francisco Census Tracts", legend = "Population", county_zoom = 6075) + coord_map()
I suspect that most people will wonder what the island off the west coast is. It is the Farallon Islands.
choroplethrCaCensusTract ships with a data.frame, df_ca_tract_demographics, that has eight demographic variables from the 2013 5-year American Community Survey (ACS).
data(df_ca_tract_demographics) ?df_ca_tract_demographics colnames(df_ca_tract_demographics)
##  "region" "total_population" "percent_white" ##  "percent_black" "percent_asian" "percent_hispanic" ##  "per_capita_income" "median_rent" "median_age"
df_ca_tract_demographics$value = df_ca_tract_demographics$per_capita_income ca_tract_choropleth(df_ca_tract_demographics, title = "2013 San Francisco Census Tracts\n Per Capita Income", legend = "Dollars", num_colors = 1, county_zoom = 6075) + coord_map()
You can get the values of the eight variables from df_ca_tract_demographics from other surveys as well. See ?get_ca_tract_demographics.
You can also map data from any table from the ACS that is available thru their API and provides data at the level of California Census Tracts. See ?ca_tract_choropleth_acs.