Mapping religious adherence in the US with CartoDB

[This article was first published on Kyle Walker, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Before coming to TCU, I worked as a data analyst for the Church Pension Group, which manages the retirement funds and provides other financial services for the Episcopal Church. I was part of a small research group that completed both internal and public-facing studies using the company’s data. You can take a look at some of the studies I worked on here. While I was at CPG, I developed an interest in the sociology of religion, as changing rates of religious adherence were of critical importance to CPG’s work, as they impact the overall viability of parishes (and in turn the fiscal health of the Church). During this time, data for the 2010 US Religion Census (or Religious Congregations and Membership Study, abbreviated as RCMS) started to become available. As the US Census does not ask questions about religion, researchers interested in studying religion must turn to other data sources like these.

I never had the opportunity to really dig into this dataset while at CPG, as I left for my current position at TCU shortly afterward. However, as I teach about the geography of religious adherence (defined here as the proportion of the population actively practicing a religion) in my World Regional Geography course, I took the opportunity to dive back into the data. I was inspired by this map from the Glenmary Research Center which maps the top religious family by county in the United States. This map is excellent, but I wanted an interactive version that I could explore with my students in class (and that they could explore outside of class). However, I did really like the bivariate cartographic technique they used to present the data (see this post from Joshua Stevens for a great overview of bivariate mapping). In this instance, the top religious group in each county is assigned a color; then, the intensity of the color is related to the adherence percentage for that group. This makes sense; if two counties have Catholic as their top group, but one has an adherence of 75 percent as opposed to 20 percent for the other, they should not be represented the same way.

There are many other examples of this type of cartographic approach. Some excellent examples have come from Steven Romalewski and CUNY’s Center for Urban Research, where they have mapped demographic change and election results. I use the demographic map in my teaching every semester to discuss issues of gentrification and demographic inversion in metropolitan areas. In the CUNY maps, the qualitative color of a feature represents the most prevalent group (e.g. race) and then the intensity of the hue represents its relative value (the percentage represented by that racial group).

A related approach is value-by-alpha, which works in a similar way in that the color of a feature represents one attribute, and its opacity represents an equalizing attribute, like total population. You can read more about Andy Woodruff’s fine work on the topic here, here, and here.

I borrow from these approaches to map religious adherence by county using CartoDB, a phenomenal web-based platform for creating interactive maps. CartoDB’s functionality ranges from the creation of simple maps with a user-friendly web UI to actual GIS functionality using its PostGIS backend with spatial SQL. Here is the map I created; below, I’ll explain how I did it! Use the arrows button in the upper left to pop the map out to full screen; click here if you’d like a direct link to the map.

The map shows the top religious adherence group by county, with some key differences from the Glenmary map; I classified the data as Catholic, Evangelical Protestant, Latter-Day Saints (Mormon), Mainline Protestant, and Black Protestant. No other major category was the top group in the lower 48 states plus DC. I used R to process the data; I won’t go into detail about that here, but you can view the code in my GitHub repository. The whole process can be reproduced by cloning the repo, running the script, and zipping up the new shapefile cty_religion for uploading to CartoDB.

Uploading your data to CartoDB is straightforward: once your data are in the right format (in this instance, in the form of a zipped shapefile), just sign in and drag and drop! Once your data have loaded, CartoDB includes a number of “wizards” you can use to style your data in a very user-friendly way. For more complex visualizations, however, you can use CartoCSS. CartoCSS, which is also used by MapBox Studio (another new favorite of mine), is a CSS-like syntax for styling map data. It also makes bivariate visualizations possible. To style the map, I grabbed some colors from ColorBrewer and used the following syntax:

#cty_religion {
   line-color: #FFF;
   line-width: 1;
   line-opacity: 1;
}

#cty_religion[religion="Evangelical"] {
   polygon-fill: #e41a1c;
}
#cty_religion[religion="Catholic"] {
   polygon-fill: #377eb8;
}
#cty_religion[religion="Mainline"] {
   polygon-fill: #4daf4a;
}
#cty_religion[religion="LDS"] {
   polygon-fill: #984ea3;
}
#cty_religion[religion="African-American"] {
   polygon-fill: #ff7f00;
}

#cty_religion[percent >= 0] {
  polygon-opacity: 0.2; 
}
#cty_religion[percent >= 20] {
  polygon-opacity: 0.4;
}
#cty_religion[percent >= 30] {
  polygon-opacity: 0.6;
}
#cty_religion[percent >= 40] {
  polygon-opacity: 0.8;
}

The polygon-fill method is used to style my data by religious category with colors; the polygon-opacity method then adjusts the opacity of the features, which then blend with the light-gray CartoDB basemap to show relative intensity. I used, roughly, a quantile classification scheme with four bins (with some slight rounding to 20, 30, and 40) for this. The map, I feel, shows clear trends in religious adherence in the US. The South is the Evangelical center of the country; Catholicism is more prevalent along the US/Mexico border and in the Northeast, Utah is a Mormon stronghold, and Mainline Protestantism predominates in the Upper Midwest. The bivariate approach also gives the viewer a sense of the relative religiosity of different places; whereas Utah and the Southeast appear to have much stronger adherence to their top religious groups, the opacity of features in the Northwest suggests lower religiosity there (or at least no group that is significant numbers-wise).

There is a lot more I’d like to do with this map; here are some ideas:

  • I’ve restricted this to the lower 48 states plus DC; Alaska and Hawaii should be added.
  • I’d like a better legend that shows variation in intensity as well as hue; I experimented with this a little but couldn’t quite get anything satisfactory working.
  • It would be great to have an interactive chart appear upon clicking each county that shows the overall distribution of each group; this is beyond my current CartoDB.js skills but something to consider for a future iteration.

If you have any comments or questions, please let me know!

Thanks to:

  • Steven Romalewski and the CUNY Center for Urban Research for their innovative approaches to bivariate mapping
  • Andy Woodruff and others for resources on the value-by-alpha technique
  • CartoDB
  • The Association of Religion Data Archives for providing free access to the RCMS data
  • NHGIS at the University of Minnesota for the spatial data
  • The Glenmary Research Center for inspiring this map

To leave a comment for the author, please follow the link and comment on their blog: Kyle Walker.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)