Mobility & Unrest in South Africa

[This article was first published on R | datawookie, 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.

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.


Load the package.



What regions are covered by the data?

  [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 x 4
   iso   country      region        data                    
   <chr> <chr>        <chr>         <list>                  
 1 ZA    South Africa <NA>          <tibble[,3] [3,132 × 3]>
 2 ZA-EC South Africa Eastern Cape  <tibble[,3] [3,132 × 3]>
 3 ZA-FS South Africa Free State    <tibble[,3] [3,132 × 3]>
 4 ZA-GT South Africa Gauteng       <tibble[,3] [3,132 × 3]>
 5 ZA-NL South Africa KwaZulu-Natal <tibble[,3] [3,132 × 3]>
 6 ZA-LP South Africa Limpopo       <tibble[,3] [3,132 × 3]>
 7 ZA-MP South Africa Mpumalanga    <tibble[,3] [3,132 × 3]>
 8 ZA-NW South Africa North West    <tibble[,3] [3,132 × 3]>
 9 ZA-NC South Africa Northern Cape <tibble[,3] [3,132 × 3]>
10 ZA-WC South Africa Western Cape  <tibble[,3] [3,132 × 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 x 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.


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.

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

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.

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 major 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.

To leave a comment for the author, please follow the link and comment on their blog: R | datawookie. 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)