R
SF
Map
Africa
Author

George Girton

Published

October 26, 2023

I guess technically the Dodo died off in Africa, but do you know in which country?

Dodo bird seen in Muséum National d’Histoire Naturelle

The Dodo lived, up until humans settled the island, only on the island of Mauritius – named after Dutch Prince Maurice – but Mauritius, 1000 nautical miles east of the African mainland, would not become an independent country until 300 years after the last Dodo sighting.

In the years since I saw the Dodo pictured above, the Museum have done a much better Dodo reconstitution:
Dodo aujourd'hui au Muséum National d’Histoire Naturelle
In addition to the much-better feathers, notice the longer legs.

Getting back to our story, a college classmate donates childrens books to Africa to help create libraries. One book, “Africa, amazing Africa (2021)” by Atinuke, has a page describing each country with a bit of art. I ordered it ‘on hold’ from the library (X 960 A872), and while waiting for it to arrive, gave myself the Africa Challenge quiz.

I wrote the names of as many African countries as I could remember on an 8.5 x 11 sheet, roughly in the shape of Africa. I mean, I didn’t do THAT badly, but I missed two large countries, with about a third of Africa’s population between them. And I didn’t get close to half the countries.

I’m not showing you the paper because … wouldn’t that ruin it for you? … I want you to take the challenge yourself!

So then, I downloaded country boundaries, to look at countries in Africa. You can go to Natural Earth and get them too. I loaded them into R Studio, and with just a few lines of code in R, I made the maps on this page.

Code
all_countries <- read_sf(dsn="Geobook/Countries", layer="ne_10m_admin_0_countries")

# Check out what types of regionalization are in the file

unique(all_countries$REGION_UN)
[1] "Asia"       "Americas"   "Africa"     "Europe"     "Oceania"   
[6] "Antarctica"
Code
unique(all_countries$REGION_WB)
[1] "East Asia & Pacific"        "Latin America & Caribbean" 
[3] "Europe & Central Asia"      "South Asia"                
[5] "Middle East & North Africa" "Sub-Saharan Africa"        
[7] "North America"              "Antarctica"                
Code
Africa <- all_countries |> filter(REGION_UN == "Africa")


## So, that's Africa

Africa |> 
  ggplot() +
  geom_sf()

Code
## And the dodo ...
 Dodohome <- Africa |> filter(ADMIN=='Mauritius')

 paste("Human population of Mauritius:", Dodohome$POP_EST, " (Dodo population: 0.0)")
[1] "Human population of Mauritius: 1265711  (Dodo population: 0.0)"
Code
NorthAfricaMidEast <- all_countries |> 
  filter(REGION_WB == 'Middle East & North Africa')

NorthAfricaMidEast |> ggplot() + geom_sf()

Code
AfricaSub <- all_countries |> filter(REGION_WB == 'Sub-Saharan Africa')
AfricaSub |> ggplot() + geom_sf()

Ancestry numbers

As chance would have it, I had a list of estimates of the people in the United States who say they, or their ancestors, are from particular countries in Africa.

Now, read the names and numbers.

 [1] "Albania"                 "Armenia"                
 [3] "Australia/New Zealand"   "Austria"                
 [5] "Baltic"                  "Basque"                 
 [7] "Belgium"                 "Bulgaria"               
 [9] "Croatia"                 "Czech Republic"         
[11] "Denmark"                 "Holland"                
[13] "Eastern European (nec)"  "England"                
[15] "European (nec)"          "Finland"                
[17] "France"                  "Germany"                
[19] "Greece"                  "Hungary"                
[21] "Iceland"                 "Ireland"                
[23] "Italy"                   "Norway"                 
[25] "Poland"                  "Portugal"               
[27] "Romania"                 "Russia"                 
[29] "Scandinavia"             "Scotland"               
[31] "Serbiaa"                 "Slovakia"               
[33] "Slovenia"                "Sweden"                 
[35] "Switzerland"             "Ukraine"                
[37] "Yugoslavia"              "Afghanistan"            
[39] "Assyria"                 "Iran"                   
[41] "Israel"                  "Turkey"                 
[43] "Egypt"                   "Iraq"                   
[45] "Jordan"                  "Lebanon"                
[47] "Morocco"                 "Palestine"              
[49] "Syria"                   "Arabia (nec)"           
[51] "Africa"                  "Cabo Verde"             
[53] "Ethiopia"                "Ghana"                  
[55] "Kenya"                   "Liberia"                
[57] "Nigeria"                 "Somalia"                
[59] "South Africa"            "Sudan"                  
[61] "Subsaharan Africa (nec)" "Brazil"                 
[63] "Dutch West Indes"        "Guyana"                 
[65] "Haiti"                   "Jamaica"                
[67] "West Indes (nec)"       
[1] 1861810
[1] 2101250
[1] "5. Low income"           "4. Lower middle income" 
[3] "3. Upper middle income"  "2. High income: nonOECD"

In order to display it on the map, join it with the Geometry table.

Code
combined_data <- left_join(Africa,fromCountry, by = c("NAME" = "Country"))


combined_data %>% 
  ggplot(aes(fill = USTotal)) +
  geom_sf(color = NA) +
  scale_fill_viridis_b() +
  theme_void()

Shaded yellow, you can see the biggest one is Nigeria. Also large: Sudan just south of Egypt.

Now for 2022ACS

In table BO4006, you can download the Census Bureau’s current-year estimates of the same data. So … I did that too!

I made a plotly map from the code, trying to show ancestry estimate when you “fly your mouse” over the country. It works a lot better on your computer screen than on youc phone screen!

Code
options(scipen=999)

PRA2022 <- read_csv("BO4006.csv") 
Rows: 105 Columns: 4
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
chr (2): Label, SummaryGroup
dbl (2): Estimate, Margin of Error

ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Code
combined_2022 <- combined_data |> left_join(PRA2022, by= c("Ancestry" = "Label"))

wrappable_plot <- combined_2022 |> 
  ggplot(aes(fill=Estimate, text = str_c("from ", NAME, ": ", Estimate))) + 
  geom_sf(color=NA) +
  scale_fill_viridis_b() +
  theme_void()

ggplotly(wrappable_plot, # wrap static map in # ggplotly()
        tooltip = "text" # (The text aesthitic on hover, hover does not work that great)
)