Function Repository Resource:

GoogleMobilityReport

Source Notebook

Generate a dataset from Google Community Mobility Reports for a given country

Contributed by: Mads Bahrami (Wolfram Research)

ResourceFunction["GoogleMobilityReport"][country]

generate a Dataset for country from Google Community Mobility Reports.

Details

The argument country can be a string (name of a country or its ISO 3166-1 alpha-2 code) or an Entity of the type "Country".
ResourceFunction["GoogleMobilityReport"][country] generates a Dataset from the Google reports on movement trends over time by geography across different categories of places such as retail and recreation, groceries and pharmacies, parks, transit stations, workplaces and residential. The mobility reports are given as TimeSeries for these categories.
The properties (column names) of the Dataset are as follows:
"Country"the corresponding country
"SubRegion1"level 1 administrative divisions within a country (e.g. US states)
"SubRegion2"level 2 administrative divisions of an administrative division of level 1 (e.g. US counties)
"MetroArea"corresponding metropolitan areas, if any
"RetailAndRecreation"mobility trends for places like restaurants, cafes, shopping centers, theme parks, museums, libraries and movie theaters
"GroceryAndPharmacy"mobility trends for places like grocery markets, food warehouses, farmers markets, specialty food shops, drug stores and pharmacies
"Parks"mobility trends for places like local parks, national parks, public beaches, marinas, dog parks, plazas and public gardens
"TransitStations"mobility trends for places like public transport hubs such as subway, bus and train stations
"Workplaces"mobility trends for places of work
"Residential"mobility trends for places of residence
According to the Google documentation on this data, changes for each day are compared to a baseline value for that day of the week. The baseline is the median value for the corresponding day of the week during the 5-week period Jan 3–Feb 6, 2020.
The data wrangling of some countries with many subregions (e.g., USA) may be a time-consuming process.

Examples

Basic Examples (3) 

Get the data of United Arab Emirates:

Look at three random rows of the Dataset:

In[1]:=
uae[RandomInteger[Length[uae], 3]]
Out[1]=

Visualize the data for the city of Dubai:

In[2]:=
Multicolumn[
 KeyValueMap[
   DateListPlot[{#2}, PlotLabel -> #1, Sequence[
     Joined -> {True, False}, Filling -> {1 -> Axis, 2 -> {Axis, 
Directive[
Opacity[0.5], Red, Thick]}}, AspectRatio -> 1/2, FrameTicks -> {{{{-80, "-80%"}, {-40, "-40%"}, {0, "Baseline"}, {40, "+40%"}, {80, "+80%"}}, None}, Automatic},
       ImageSize -> Medium, GridLines -> {None, {-80, -40, 0, 40, 80}},
       PlotStyle -> {Automatic, None}, PlotRange -> {-100, 100}]] &][
  Normal[uae[SelectFirst[#SubRegion1 == "Dubai" &]]][[-6 ;;]]], 3]
Out[2]=

Possible Issues (1) 

Google reports do not contain all countries:

In[3]:=
ResourceFunction["GoogleMobilityReport"]["Iran"]
Out[3]=

Neat Examples (2) 

Get the data of United Arab Emirates:

A manipulate comparing the latest value of mobility reports in UAE:

In[4]:=
Manipulate[
 GeoRegionValuePlot[
  dt[All, {"SubRegion1", report}][
   Values, {#[[1]], #[[2]]["LastValue"]} &]], {{report, "RetailAndRecreation", "Report"}, {"RetailAndRecreation", "GroceryAndPharmacy", "Parks", "TransitStations", "Workplaces", "Residential"}}, Initialization :> {dt = uae[Rest, {"SubRegion1" -> Interpreter["AdministrativeDivision"]}]}, SaveDefinitions -> True]
Out[4]=

Publisher

Wolfram Summer Camp

Version History

  • 1.2.0 – 19 April 2021
  • 1.1.0 – 18 March 2021
  • 1.0.0 – 11 February 2021

Source Metadata

Related Resources

License Information