ArcGIS Online

Create a diversity map with Arcade

Arcade is an expression language that allows you to define custom content in ArcGIS applications for desktop, mobile, and the web. Arcade expressions give you the flexibility to create dynamic popup elements, calculate new values, and format data. In this post, I’ll demonstrate how you can use Arcade to map diversity.

First, I’ll provide details describing my methodology, then we’ll explore the results with a ton of maps.

Diversity index

When the 2020 United States Census numbers were released, the summary of responses showed the U.S. is more diverse than ever. In the context of demographics, diversity usually refers to the level of variation that exists in a population with respect to race and ethnicity.

In fact, Esri provides a diversity index that returns a value between 0-100 for each census tract in the U.S. A diversity index indicates the probability that two people selected at random within an area belong to a different race or ethnicity. Therefore, higher numbers indicate more diversity.

Racial and ethnic diversity of the southeastern United States (2021).
Racial and ethnic diversity of the southeastern United States (2021 Esri Diversity Index). Overall, the United States has a diversity index of 62. This means there is a 62 percent chance that two people selected at random within the entire United States have a different race or ethnicity.

Languages spoken at home

Occasionally I like to explore data in the ArcGIS Living Atlas of the World. The Living Atlas has a treasure trove of data, including up-to-date data from the American Community Survey (ACS). I load the data in the ArcGIS Online Map Viewer to see if I can learn something new by experimenting with various Smart Mapping styles.

Recently, I came across this layer containing data for languages spoken in the home. It reports the number of people speaking languages in the following categories:

I loaded the layer in the ArcGIS Online Map Viewer and created a predominance map. A predominance map shows which language group is most common among the people living in an area. Southern California immediately revealed interesting patterns.

Click here to open the web map

Predominant language spoken in the home in southern California. I learned the purple areas (predominantly Indo-European languages spoken in the home) in Glendale coincide with high Armenian populations in the area.
Predominant language spoken in the home in southern California. I learned the purple areas (predominantly Indo-European languages spoken in the home) in Glendale coincide with high Armenian populations in the area.

While exploring this map, I immediately thought about diversity — not in the context of race and ethnicity — but of languages. Since language diversity isn’t a field contained in this layer, I decided to write an Arcade expression to create a language diversity index. Arcade provides an avenue to calculate any value within the context of the map even though I don’t own this data.

As opposed to predominance, which focuses on the most common category, a diversity map will communicate the variety within the area. Low diversity areas will coincide with areas that show strong predominance for one category.

Simpson’s Diversity Index

I chose Simpson’s Diversity Index to calculate diversity using Arcade. While Simpson’s Diversity Index is typically used to calculate biodiversity, it can also be used to calculate diversity for demographics in human populations.

Simpson's diversity index.
The formula defining Simpson's Diversity Index.

This formula returns a number between 0 – 1, indicating the probability that two individuals selected at random belong to different groups or categories. The higher the score, the higher the diversity in the area for the given variables.

I wrote the following function in Arcade to calculate Simpson’s Diversity Index for any set of categories within a population. For readability within the map, I decided to multiply the final index by 100 (e.g. representing probability as 50% is easier to read than 0.5).

// Returns a value between 0-100.
// Indicates the % chance two people
// who speak different langages are
// randomly selected from the area.
function simpsonsDiversityIndex(vals){
  var k = Array(Count(vals));
  var t = sum(vals);
  for(var i in vals){
    var n = vals[i];
    k[i] = n * (n-1);
  }
  var s = Sum(k);
  var di = 1 - ( s  / ( t * (t-1) ) );
  return Round(di*100);
}

Let’s input a few test values to see how this index works. If there are five groups, where one has 100 individuals and the others each have zero, the function will return 0. This indicates there is no diversity since all individuals come from a single group.

Simpson's diversity index calculation that retuns an index of 0.

Conversely, maximum diversity is indicated by all groups having the same population. To test this, I provided the function with five groups, each with 100 individuals. It returns an index of 80. In other words, there is an 80 percent chance that two individuals selected at random will come from different groups.

Simpson's diversity index result that returns 80, the highest possible score when 5 groups are considered.

Note that there can never be a result of 1 (or 100%). The highest possible score returned from Simpson’s Diversity Index will always be (n - 1) / n, where n is the number of categories considered.

Therefore, a higher number of categories combined with similar populations in each category will result in a higher diversity index.

Mapping language diversity

Once the function was written, I referenced the total number of people in each language category as inputs to the function.

var asian = $feature["B16007_calc_numAPIE"];
var english = $feature["B16007_calc_numEngOnlyE"];
var european = $feature["B16007_calc_numIEE"];
var other = $feature["B16007_calc_numOtherE"];
var spanish = $feature["B16007_calc_numSpanE"];

var languages = [asian, english, european, other, spanish];

function simpsonsDiversityIndex(vals){
  var k = Array(Count(vals));
  var t = sum(vals);
  for(var i in vals){
    var n = vals[i];
    k[i] = n * (n-1);
  }
  var s = Sum(k);
  var di = 1 - ( s  / ( t * (t-1) ) );
  return Round(di*100);
}

simpsonsDiversityIndex(languages);

Clicking OK in the Arcade editor executes the expression for each feature in the layer. Once the expression finishes, a style is created based on statistics summarizing the output for all features. Selecting an above-and-below theme reveals the following map.

Language diversity in southern California. Higher numbers indicate a higher probability that two people selected at random in the area will speak languages from different categories.
Language diversity in southern California. Higher numbers indicate a higher probability that two people selected at random in an area will speak languages from different categories.

Brown areas indicate areas of high language diversity, or areas where people are more likely to live close to others who speak a different language than themselves. The green areas indicate areas of low language diversity, or areas where people are more likely to speak the same language as their neighbors.

As a whole, most tracts in the United States have low language diversity because most people speak English in the home. Areas with the highest language diversity tend to be in large cities, with the exception of cities in the Midwest.

Language diversity in the United States. The vast majority of the population speaks English in the home. Areas with high language diversity tend to be in large cities along coastlines.
Language diversity in the United States. The vast majority of the population speaks English in the home. Areas with high language diversity tend to be in large cities along coastlines.

The following maps explore language diversity compared with maps showing the predominant language group spoken in the home in a few select cities. The size of the circles in each map corresponds to the total population ages 5 and older in the area.

Click each image to enlarge it for readability.

Click here to view the live web map and explore the data on your own.

Language diversity in San Francisco and surrounding cities.
Language diversity in San Francisco and surrounding cities.
Predominant language groups spoken in the home in San Francisco and surrounding cities.
Predominant language groups spoken in the home in San Francisco and surrounding cities.
Language diversity in New York City.
Language diversity in New York City.
Predominant language group spoken in the home in New York City.
Predominant language group spoken in the home in New York City.
Language diversity in Miami.
Language diversity in Miami.
Predominant language group spoken in the home in Miami.
Predominant language group spoken in the home in Miami.
Language diversity in Chicago.
Language diversity in Chicago.
Predominant language group spoken in the home in Chicago.
Predominant language group spoken in the home in Chicago.

Open this app to explore this data in other parts of the United States using a Swipe widget.

Language diversity in areas with high Spanish and English speaking populations

If I add the total Spanish speaking population as a second variable to the layer’s style, the Map Viewer will replace the fill symbols with marker symbols. The larger the size of the symbol, the higher the number of Spanish speakers in the tract.

Therefore, the maps below show the number of Spanish and English speakers in each area within the context of overall language diversity.

Click here to open the map

The probability that two people selected at random speak different languages in areas with a large number of Spanish speakers. Large green circles in central Los Angeles show large populations of Spanish speakers that are more likely to live amongst others who speak Spanish. Large brown circles indicate areas of large Spanish speaking populations that likely live amongst people who speak languages other than Spanish.
The probability that two people selected at random speak languages from different categories in areas with a large number of Spanish speakers. Large green circles in central Los Angeles show large populations of Spanish speakers that are more likely to live amongst others who speak Spanish. Large brown circles indicate areas of large Spanish speaking populations that likely live amongst people who speak languages other than Spanish.
The probability that two people, selected at random, speak languages from different categories in areas with a large number of English speakers.
The probability that two people, selected at random, speak languages from different categories in areas with a large number of English speakers.

Diversity of specific Asian groups

The Living Atlas recently added layers containing the populations of specific Asian groups at the state, county, and tract levels. Many people in these groups speak different languages, but are represented within a single category in the languages layer. Because of this, I was eager to explore the diversity that exists within Asian populations.

I used the same Simpson’s Diversity Index Arcade function in the layer’s style. However, this time I referenced numbers from 23 specific Asian groups and created the following map.

Click to expand and view the expression
var indian = $feature["B02018_002E"];
var bangladeshi = $feature["B02018_003E"];
var bhutanese = $feature["B02018_004E"];
var burmese = $feature["B02018_005E"];
var cambodian = $feature["B02018_006E"];
var chinese = $feature["B02018_007E"];
var filipino = $feature["B02018_008E"];
var hmong = $feature["B02018_009E"];
var indonesian = $feature["B02018_010E"];
var japanese = $feature["B02018_011E"];
var korean = $feature["B02018_012E"];
var laotian = $feature["B02018_013E"];
var malaysian = $feature["B02018_014E"];
var mongolian = $feature["B02018_015E"];
var nepalese = $feature["B02018_016E"];
var okinawan = $feature["B02018_017E"];
var pakistani = $feature["B02018_018E"];
var srilankan = $feature["B02018_019E"];
var taiwanese = $feature["B02018_020E"];
var thai = $feature["B02018_021E"];
var vietnamese = $feature["B02018_022E"];
var other = $feature["B02018_023E"] + $feature["B02018_024E"];


var groups = [ indian, bangladeshi, bhutanese, burmese, cambodian,
  chinese, filipino, hmong, indonesian, japanese, korean, laotian,
  malaysian, mongolian, nepalese, okinawan, pakistani, srilankan,
  taiwanese, thai, vietnamese, other];

// Returns a value 0-100.
// Indicates the % chance two people
// from different Asian regions are
// randomly selected from the area.
function simpsonsDiversityIndex(vals){
  var k = Array(Count(vals));
  var t = sum(vals);
  for(var i in vals){
    var n = vals[i];
    k[i] = n * (n-1);
  }
  var s = Sum(k);
  var di = 1 - ( s  / ( t * (t-1) ) );
  return Round(di*100);
}

simpsonsDiversityIndex(groups);

Click to open this map

Diversity of Asian specific groups in the United States. Brown areas indicate areas where people of Asian origin are more likely to live close to Asians from other groups.
Diversity of Asian specific groups in the United States. Brown areas indicate areas where people of Asian origin are more likely to live close to Asians from other groups.

The results show very high diversity in many parts of the U.S. However, several areas in large metropolitan areas, like Los Angeles, Chicago, and New York, reveal neighborhoods with high Asian American populations and low diversity. For example, these include the following communities in Los Angeles: China Town, Little Tokyo, Little Saigon, Korea Town, Little Manila, and Cambodia Town.

Check out the diversity of specific Asian groups in the following maps.

Click each image to enlarge it for readability.

Click to open this map

Diversity of specific Asian groups in Los Angeles.
Diversity of specific Asian groups in Los Angeles.
Diversity of specific Asian groups in San Francisco.
Diversity of specific Asian groups in San Francisco.
Diversity of specific Asian groups in New York.
Diversity of specific Asian groups in New York.
Diversity of specific Asian groups in Chicago.
Diversity of specific Asian groups in Chicago.

These maps clearly show the high diversity that exists within Asian populations on their own.

Predominant Asian groups

The predominance style reveals the predominant group of each low diversity area. Because I can only map up to 10 categories with predominance, I chose to consider only the most populous categories as reported by the Pew Research Center.

Click here to open this map

Click each image to enlarge it for readability.

Predominant group among Asian populations in southern California.
Predominant group among Asian populations in southern California.
Predominant group among Asian populations in New York City.
Predominant group among Asian populations in New York City.
Predominant group among Asian populations in San Francisco, CA.
Predominant group among Asian populations in San Francisco, CA.
Predominant group among Asian populations in Chicago.
Predominant group among Asian populations in Chicago.

The default popup on these layers displays a chart visualizing the populations of each group relative to one another. A single tall bar indicates low diversity populations. Several bars indicate more diversity in the population.

Adding a bar chart to the popup can also help communicate diversity in a population.
Adding a bar chart to the popup can also help communicate diversity in a population.

To learn more about the demographics of Asian Americans in the United States, check out the following article from the Pew Research Center.

Key facts about Asian Americans, a diverse and growing population

Diversity of Hispanic and Latino groups

The Living Atlas also recently added a layer containing data describing the number of people belonging to specific Hispanic and Latino groups. This includes 25 unique categories from regions of South America, Central America, Mexico, the Caribbean islands, and Spain.

The results almost look like the inverse of the map of diversity among specific Asian groups. Most census tracts in the United States show low diversity among Hispanic and Latino groups. High population areas in Florida and the east coast are exceptions.

Click to view this map

Click each image to enlarge it for readability.

Diversity of specific Hispanic/Latino groups in the United States.
Diversity of specific Hispanic/Latino groups in the United States.

The predominance map for the same extent shows that most people of Hispanic origin in the United States are Mexican.

Predominant Hispanic/Latino group by Census Tract in the United States.
Predominant Hispanic/Latino group by Census Tract in the United States.

However, Florida and New York have high populations from other Hispanic/Latino groups, making them perhaps the most diverse areas among Hispanic and Latino populations.

Diversity of specific Hispanic/Latino groups in Florida.
Diversity of specific Hispanic/Latino groups in Florida.
Diversity of specific Hispanic/Latino groups in Miami.
Diversity of specific Hispanic/Latino groups in Miami.
Diversity of specific Hispanic/Latino groups in New York City.
Diversity of specific Hispanic/Latino groups in New York City.
Diversity of specific Hispanic/Latino groups in San Francisco.
Diversity of specific Hispanic/Latino groups in San Francisco.
Diversity of specific Hispanic/Latino groups in southern California.
Diversity of specific Hispanic/Latino groups in southern California.

The following maps show predominant Hispanic/Latino populations considering the most common groups as reported by the Pew Research Center, and groups within Central and South American subgroups.

Predominant Hispanic/Latino groups

Click to view this map

Click each image to enlarge it for readability.

Predominant Hispanic/Latino group in southern California.
Predominant Hispanic/Latino group in southern California.
Predominant Hispanic/Latino group in San Francisco.
Predominant Hispanic/Latino group in San Francisco.
Predominant Hispanic/Latino group in New York City.
Predominant Hispanic/Latino group in New York City.
Predominant group among Hispanic/Latino populations in Florida.
Predominant group among Hispanic/Latino populations in Florida.
Predominant Hispanic/Latino group in Miami.
Predominant Hispanic/Latino group in Miami.
Predominant Hispanic/Latino group of Central American origin in Miami.
Predominant Hispanic/Latino group of Central American origin in Miami.
Predominant Hispanic/Latino group of South American origin in Miami.
Predominant Hispanic/Latino group of South American origin in Miami.

To learn more about the demographics of people of Hispanic/Latino origin in the United States, check out the following article from the Pew Research Center.

Key facts about U.S. Latinos for National Hispanic Heritage Month

Explore these maps on your own

The following apps allow you to explore diversity and compare it with predominance for each of the variables described in this post. I encourage you to explore the data in each to learn more about the diversity that exists within each each category.

Click this image to explore the diversity of specific Hispanic/Latino groups compared with languages spoken in the home.
Click this image to explore the diversity of specific Hispanic/Latino groups compared with languages spoken in the home.

Conclusion

The term diversity intentionally focuses on the differences that exist in a population. This may include differences in race, ethnicity, language, culture, religion, age, gender and many other categories. As I reflect on my associations and friendships with neighbors, coworkers, and other associates from all sorts of backgrounds, I am reminded of two things:

  1. We are alike in many ways; we are all human, and experience the same emotions (though through different life experiences, which leads to the second point).
  2. We are all truly unique whether or not we have similar backgrounds or belong to the same demographic categories; our uniqueness shows we our more diverse than data often indicate.

While the maps I shared above focus on the diversity of specific categories, don’t forget that more diversity exists in each area than the data actually reports.

Creating a diversity index is just one of many examples where you can use Arcade to calculate new values to display custom content in web maps. I encourage you to read other posts focusing on how you can use Arcade to customize your maps.

About the author

Kristian is a Senior Product Engineer at Esri. His work focuses on data visualization and Arcade integration in the ArcGIS API for JavaScript. His goal is to help developers be successful, efficient, and confident in building web applications with the JS API, especially when it comes to visualizing data. Prior to joining Esri he worked as a GIS Specialist for an environmental consulting company. He enjoys cartography, GIS analysis, and building GIS applications for genealogy.

Connect:
0 Comments
Inline Feedbacks
View all comments

Next Article

Deprecation of Complimentary accounts in ArcGIS Maps for Adobe Creative Cloud

Read this article