Mobility & Unrest in South Africa

A highway with mountains on the horizon.

Did the recent unrest in South Africa have a detectable effect on mobility patterns?

Google Mobility Data

Google has used anonymised data personal location data to gather information on mobility during the COVID-19 pandemic. These data are freely available in CSV format and regularly updated.

{mobility} Package

I created a small R package, {mobility}, which wraps the Google Mobility Data. The package is available from GitHub and the data are updated daily using GitHub Actions. This package makes it easy to delve into these data from R.

Installing & Loading the Package

Install the package.

remotes::install_github("datawookie/mobility")

Load the package.

library(mobility)

Regions

What regions are covered by the data?

regions
  [1] "AE" "AF" "AG" "AO" "AR" "AT" "AU" "AW" "BA" "BB" "BD" "BE" "BF"
 [14] "BG" "BH" "BJ" "BO" "BR" "BS" "BW" "BY" "BZ" "CA" "CH" "CI" "CL"
 [27] "CM" "CO" "CR" "CV" "CZ" "DE" "DK" "DO" "EC" "EE" "EG" "ES" "FI"
 [40] "FJ" "FR" "GA" "GB" "GE" "GH" "GR" "GT" "GW" "HK" "HN" "HR" "HT"
 [53] "HU" "ID" "IE" "IL" "IN" "IQ" "IT" "JM" "JO" "JP" "KE" "KG" "KH"
 [66] "KR" "KW" "KZ" "LA" "LB" "LI" "LK" "LT" "LU" "LV" "LY" "MA" "MD"
 [79] "MK" "ML" "MM" "MN" "MT" "MU" "MX" "MY" "MZ" "NA" "NE" "NG" "NI"
 [92] "NL" "NO" "NP" "NZ" "OM" "PA" "PE" "PG" "PH" "PK" "PL" "PR" "PT"
[105] "PY" "QA" "RE" "RO" "RS" "RU" "RW" "SA" "SE" "SG" "SI" "SK" "SN"
[118] "SV" "TG" "TH" "TJ" "TR" "TT" "TW" "TZ" "UA" "UG" "US" "UY" "VE"
[131] "VN" "YE" "ZA" "ZM" "ZW"

The regions variable contains all of the included geographic regions using two letter ISO country codes.

Mobility Data per Region

Using the mobility() function you can retrieve the data for a specific region.

mobility_za <- mobility("ZA")
# A tibble: 10 × 4
   iso    country      region        data                
   <chr>  <chr>        <chr>         <list>              
 1 ZA     South Africa <NA>          <tibble [4,134 × 3]>
 2 ZA-EC  South Africa Eastern Cape  <tibble [4,134 × 3]>
 3 ZA-FS  South Africa Free State    <tibble [4,134 × 3]>
 4 ZA-GP  South Africa Gauteng       <tibble [4,134 × 3]>
 5 ZA-KZN South Africa KwaZulu-Natal <tibble [4,134 × 3]>
 6 ZA-LP  South Africa Limpopo       <tibble [4,134 × 3]>
 7 ZA-MP  South Africa Mpumalanga    <tibble [4,134 × 3]>
 8 ZA-NW  South Africa North West    <tibble [4,134 × 3]>
 9 ZA-NC  South Africa Northern Cape <tibble [4,134 × 3]>
10 ZA-WC  South Africa Western Cape  <tibble [4,134 × 3]>

The time series data, which reflect the percentage change relative to a baseline, are nested in the data column and have been pivoted into long format.

# A tibble: 12 × 3
   date       place               change
   <date>     <fct>                <dbl>
 1 2020-02-15 retail & recreation      4
 2 2020-02-15 grocery & pharmacy       0
 3 2020-02-15 parks                   -2
 4 2020-02-15 transit stations        -2
 5 2020-02-15 workplaces               1
 6 2020-02-15 residential             -2
 7 2020-02-16 retail & recreation     -3
 8 2020-02-16 grocery & pharmacy      -1
 9 2020-02-16 parks                  -10
10 2020-02-16 transit stations        -6
11 2020-02-16 workplaces              -1
12 2020-02-16 residential              0

You can also get the data for all regions.

mobility()

The mobility() function is memoised. The first time that it’s run there’s some delay while it constructs the data. The next time around it’s fast.

South Africa Mobility & COVID-19

Let’s calibrate our expectations by looking at the movements of people in South Africa to various places since the onset of the pandemic.

Changes in mobility in South Africa between March 2020 and August 2021.

It’s clear that people are spending a lot more time at home and much less time at work.

To put these data into perspective I’ll overlay some relevant dates using the history data from the {saffer} package.

Changes in movement for retail & recreation in South Africa with historical dates from {saffer} package overlaid.

KwaZulu-Natal Unrest

During July 2021 there was major unrest in the province of KwaZulu-Natal, with widespread looting and violence. What effect did this have on mobility? We’ll focus our attention on the data for KwaZulu-Natal and zoom in on the months of June and July 2021.

Mobility in KwaZulu-Natal during the July 2021 unrest.

Although there was protest action on Friday 9 July 2021 it did not have a significant effect on mobility in the province. If you were travelling on a major highway (as I was) then your trip was probably disrupted, but for the majority of people this did not have a serious impact.

When the unrest kicked off on Monday 12 July 2021 (indicated by the vertical grey line in the plot) there was a dramatic effect: people (well, those people who weren’t looting and pillaging) stayed away from shops and offices, electing instead to stay safely at home. The situation returned to something resembling normality over the rest of the week as civilians grouped together to protect their neighbourhoods.

We'd like to thank the public for protecting the police and army during these trying times.