Apple Mobility Trends Data Visualization

Version 0.9
Anton Antonov
MathematicaForPrediction at WordPress​
​SystemModeling at GitHub​
April 2020

Introduction

In this notebook, we ingest and visualize the mobility trends data provided by Apple [APPL1].
We take the following steps:
1
.
Download the data.
2
.
Import the data and summarize it.
3
.
Transform the data into long form.
4
.
Partition the data into subsets that correspond to combinations of geographical regions and transportation types.
5
.
Make contingency matrices and corresponding heat-map plots.
6
.
Make nearest neighbors graphs over the contingency matrices and plot communities.
7
.
Plot the corresponding time series.

Data Description

From Apple’s page:

About This Data​
The CSV file and charts on this site show a relative volume of directions requests per country/region or city compared to a baseline volume on January 13th, 2020.
We define our day as midnight-to-midnight, Pacific time. Cities represent usage in greater metropolitan areas and are stably defined during this period. In many countries/regions and cities, relative volume has increased since January 13th, consistent with normal, seasonal usage of Apple Maps. Day of week effects are important to normalize as you use this data.
Data that is sent from users’ devices to the Maps service is associated with random, rotating identifiers so Apple doesn’t have a profile of your movements and searches. Apple Maps has no demographic information about our users, so we can’t make any statements about the representativeness of our usage against the overall population.

Observations

The observations listed in this subsection are also placed under the relevant statistics in the following sections and indicated with “Observation.”
◼
  • The directions request volumes reference date for normalization is 2020-01-13; all the values in that column are
    100
    .
  • ◼
  • From the community clusters of the nearest neighbor graphs (derived from the time series of the normalized driving directions request volume), we see that countries and cities are clustered in expected ways. For example, in the community graph plot corresponding to “{city, driving}” the cities Oslo, Copenhagen, Helsinki, Stockholm and Zurich are placed in the same cluster. In the graphs corresponding to “{city, transit}” and “{city, walking}”, the Japanese cities Tokyo, Osaka, Nagoya and Fukuoka are clustered together.
  • ◼
  • In the time series plots, the Sundays are indicated with orange dashed lines. We can see that from Monday to Thursday people are more familiar with their trips than say on Fridays and Saturdays. We can also see that on Sundays people (on average) are more familiar with their trips or simply travel less.
  • Load Packages

    In[]:=
    Import["https://raw.githubusercontent.com/antononcube/MathematicaForPrediction/master/DataReshape.m"]​​Import["https://raw.githubusercontent.com/antononcube/MathematicaForPrediction/master/Misc/HeatmapPlot.m"]

    Data Ingestion

    Apple mobile data was provided in this web page [APPL1]. (The data has to be download from that web page—there is an “agreement to terms,” etc.)
    In[]:=
    dsAppleMobility=ResourceFunction["ImportCSVToDataset"]["~/Downloads/applemobilitytrends-2020-04-14.csv"]
    Out[]=
    Observation: The directions request volume reference date for normalization is 2020-01-13; all the values in that column are
    100
    .
    Data dimensions:
    In[]:=
    Dimensions[dsAppleMobility]
    Out[]=
    {395,96}
    Data summary:
    In[]:=
    Magnify[ResourceFunction["RecordsSummary"][dsAppleMobility],0.6]
    Out[]=
    
    1 geo_type
    city
    242
    country/region
    153
    ,
    2 region
    Amsterdam
    3
    Atlanta
    3
    Auckland
    3
    Australia
    3
    Baltimore
    3
    Barcelona
    3
    (Other)
    377
    ,
    3 transportation_type
    driving
    152
    walking
    152
    transit
    91
    ,
    4 2020-01-13
    1st Qu
    100
    3rd Qu
    100
    Max
    100
    Mean
    100
    Median
    100
    Min
    100
    ,
    5 2020-01-14
    Min
    90.14
    1st Qu
    99.84
    Median
    101.78
    Mean
    102.051
    3rd Qu
    104.048
    Max
    115.04
    ,
    6 2020-01-15
    Min
    73.72
    1st Qu
    101.183
    Median
    104.19
    Mean
    104.576
    3rd Qu
    107.035
    Max
    138.
    ,
    7 2020-01-16
    Min
    74.53
    1st Qu
    102.653
    Median
    106.87
    Mean
    107.315
    3rd Qu
    110.273
    Max
    139.9
    ,
    8 2020-01-17
    Min
    83.96
    1st Qu
    108.055
    Median
    117.78
    Mean
    118.305
    3rd Qu
    127.27
    Max
    173.98
    ,
    9 2020-01-18
    Min
    69.28
    1st Qu
    100.275
    Median
    114.84
    Mean
    116.855
    3rd Qu
    130.068
    Max
    184.3
    ,
    10 2020-01-19
    Min
    43.79
    1st Qu
    86.6725
    Mean
    96.516
    Median
    97.88
    3rd Qu
    105.963
    Max
    157.28
    ,
    11 2020-01-20
    Min
    72.9
    1st Qu
    97.34
    Median
    101.21
    Mean
    102.031
    3rd Qu
    104.83
    Max
    179.09
    ,
    12 2020-01-21
    Min
    69.79
    1st Qu
    99.055
    Median
    102.93
    Mean
    104.141
    3rd Qu
    107.643
    Max
    159.86
    ,
    13 2020-01-22
    Min
    78.25
    1st Qu
    99.89
    Median
    104.32
    Mean
    105.273
    3rd Qu
    109.03
    Max
    150.62
    ,
    14 2020-01-23
    Min
    64.37
    1st Qu
    102.443
    Median
    106.03
    Mean
    106.672
    3rd Qu
    110.943
    Max
    153.1
    ,
    15 2020-01-24
    Min
    56.81
    1st Qu
    107.673
    Mean
    117.839
    Median
    118.01
    3rd Qu
    127.233
    Max
    175.98
    ,
    16 2020-01-25
    Min
    40.94
    1st Qu
    101.405
    Median
    114.97
    Mean
    117.811
    3rd Qu
    133.14
    Max
    236.75
    ,
    17 2020-01-26
    Min
    33.49
    1st Qu
    84.2875
    Mean
    94.8029
    Median
    95.59
    3rd Qu
    103.64
    Max
    170.46
    ,
    18 2020-01-27
    Min
    24.46
    1st Qu
    95.895
    Median
    100.23
    Mean
    101.023
    3rd Qu
    105.368
    Max
    173.54
    ,
    19 2020-01-28
    Min
    20.32
    1st Qu
    97.3875
    Median
    102.75
    Mean
    102.803
    3rd Qu
    107.315
    Max
    162.96
    ,
    20 2020-01-29
    Min
    19.26
    1st Qu
    98.15
    Median
    103.88
    Mean
    104.246
    3rd Qu
    109.193
    Max
    149.42
    ,
    21 2020-01-30
    Min
    19.48
    1st Qu
    101.353
    Median
    106.3
    Mean
    106.786
    3rd Qu
    112.25
    Max
    146.72
    ,
    22 2020-01-31
    Min
    17.24
    1st Qu
    109.42
    Median
    118.52
    Mean
    119.36
    3rd Qu
    129.17
    Max
    189.28
    ,
    23 2020-02-01
    Min
    16.11
    1st Qu
    103.575
    Median
    116.34
    Mean
    119.308
    3rd Qu
    133.818
    Max
    223.35
    ,
    24 2020-02-02
    Min
    15.44
    1st Qu
    85.855
    Mean
    96.3973
    Median
    98.24
    3rd Qu
    107.36
    Max
    139.13
    ,
    25 2020-02-03
    Min
    13.37
    1st Qu
    95.7775
    Mean
    100.508
    Median
    101.16
    3rd Qu
    107.058
    Max
    165.91
    ,
    26 2020-02-04
    Min
    11.07
    1st Qu
    97.905
    Mean
    102.857
    Median
    104.02
    3rd Qu
    108.72
    Max
    158.73
    ,
    27 2020-02-05
    Min
    10.79
    1st Qu
    98.3225
    Mean
    103.907
    Median
    104.03
    3rd Qu
    110.438
    Max
    148.43
    ,
    28 2020-02-06
    Min
    10.25
    1st Qu
    100.827
    Median
    106.84
    Mean
    106.932
    3rd Qu
    113.012
    Max
    166.88
    ,
    29 2020-02-07
    Min
    8.79
    1st Qu
    109.248
    Median
    119.21
    Mean
    120.006
    3rd Qu
    130.29
    Max
    196.82
    ,
    30 2020-02-08
    Min
    7.51
    1st Qu
    103.318
    Median
    118.22
    Mean
    120.873
    3rd Qu
    138.017
    Max
    220.8
    ,
    31 2020-02-09
    Min
    9.62
    1st Qu
    85.1775
    Mean
    96.3173
    Median
    96.86
    3rd Qu
    107.528
    Max
    146.32
    ,
    32 2020-02-10
    Min
    8.87
    1st Qu
    97.7025
    Median
    103.28
    Mean
    103.413
    3rd Qu
    109.88
    Max
    142.61
    ,
    33 2020-02-11
    Min
    9.18
    1st Qu
    101.36
    Mean
    105.656
    Median
    105.87
    3rd Qu
    112.055
    Max
    142.01
    ,
    34 2020-02-12
    Min
    9.14
    1st Qu
    102.94
    Mean
    108.203
    Median
    109.02
    3rd Qu
    114.753
    Max
    143.63
    ,
    35 2020-02-13
    Min
    10.39
    1st Qu
    106.923
    Mean
    113.717
    Median
    114.35
    3rd Qu
    121.165
    Max
    170.56
    ,
    36 2020-02-14
    Min
    11.04
    1st Qu
    117.455
    Median
    130.35
    Mean
    132.797
    3rd Qu
    146.025
    Max
    362.5
    ,
    37 2020-02-15
    Min
    8.44
    1st Qu
    109.107
    Median
    125.15
    Mean
    127.613
    3rd Qu
    141.235
    Max
    250.18
    ,
    38 2020-02-16
    Min
    9.87
    1st Qu
    91.95
    Mean
    104.412
    Median
    104.98
    3rd Qu
    116.023
    Max
    163.15
    ,
    39 2020-02-17
    Min
    12.87
    1st Qu
    99.95
    Median
    107.56
    Mean
    109.927
    3rd Qu
    116.86
    Max
    277.96
    ,
    40 2020-02-18
    Min
    17.04
    1st Qu
    103.363
    Median
    110.69
    Mean
    112.583
    3rd Qu
    120.003
    Max
    220.24
    ,
    41 2020-02-19
    Min
    15.81
    1st Qu
    104.19
    Median
    112.1
    Mean
    113.294
    3rd Qu
    121.048
    Max
    215.1
    ,
    42 2020-02-20
    Min
    16.82
    1st Qu
    107.048
    Median
    115.36
    Mean
    117.199
    3rd Qu
    124.36
    Max
    270.13
    ,
    43 2020-02-21
    Min
    14.96
    1st Qu
    113.788
    Median
    127.86
    Mean
    129.012
    3rd Qu
    141.113
    Max
    251.99
    ,
    44 2020-02-22
    Min
    16.1
    1st Qu
    105.033
    Median
    124.68
    Mean
    128.549
    3rd Qu
    145.44
    Max
    310.73
    ,
    45 2020-02-23
    Min
    14.75
    1st Qu
    89.88
    Median
    102.06
    Mean
    104.061
    3rd Qu
    114.263
    Max
    324.06
    ,
    46 2020-02-24
    Min
    13.79
    1st Qu
    98.0325
    Median
    104.76
    Mean
    106.995
    3rd Qu
    113.835
    Max
    271.56
    ,
    47 2020-02-25
    Min
    14.47
    1st Qu
    97.7325
    Median
    105.1
    Mean
    105.96
    3rd Qu
    112.98
    Max
    251.19
    ,
    48 2020-02-26
    Min
    15.7
    1st Qu
    98.0125
    Mean
    106.391
    Median
    106.77
    3rd Qu
    114.703
    Max
    245.11
    ,
    49 2020-02-27
    Min
    16.68
    1st Qu
    100.66
    Median
    110.02
    Mean
    110.527
    3rd Qu
    119.793
    Max
    209.83
    ,
    50 2020-02-28
    Min
    17.2
    1st Qu
    110.403
    Median
    122.21
    Mean
    123.261
    3rd Qu
    135.445
    Max
    241.87
    ,
    51 2020-02-29
    Min
    19.58
    1st Qu
    103.31
    Median
    116.52
    Mean
    121.138
    3rd Qu
    135.26
    Max
    263.15
    ,
    52 2020-03-01
    Min
    18.64
    1st Qu
    84.625
    Mean
    97.0929
    Median
    97.19
    3rd Qu
    107.785
    Max
    251.72
    ,
    53 2020-03-02
    Min
    18.92
    1st Qu
    95.375
    Mean
    101.746
    Median
    102.51
    3rd Qu
    108.263
    Max
    227.68
    ,
    54 2020-03-03
    Min
    18.76
    1st Qu
    97.59
    Mean
    103.844
    Median
    104.21
    3rd Qu
    111.525
    Max
    231.22
    ,
    55 2020-03-04
    Min
    14.76
    1st Qu
    98.4375
    Mean
    104.871
    Median
    105.44
    3rd Qu
    112.933
    Max
    236.64
    ,
    56 2020-03-05
    Min
    17.49
    1st Qu
    101.602
    Mean
    109.
    Median
    110.07
    3rd Qu
    117.74
    Max
    259.56
    ,
    57 2020-03-06
    Min
    16.56
    1st Qu
    108.833
    Median
    119.61
    Mean
    120.904
    3rd Qu
    132.418
    Max
    291.3
    ,
    58 2020-03-07
    Min
    20.32
    1st Qu
    99.675
    Median
    115.82
    Mean
    120.938
    3rd Qu
    137.333
    Max
    322.18
    ,
    59 2020-03-08
    Min
    18.07
    1st Qu
    82.32
    Median
    95.36
    Mean
    96.2266
    3rd Qu
    106.883
    Max
    279.95
    ,
    60 2020-03-09
    Min
    18.96
    1st Qu
    90.61
    Mean
    97.7392
    Median
    99.02
    3rd Qu
    106.885
    Max
    229.01
    ,
    61 2020-03-10
    Min
    17.53
    1st Qu
    89.925
    Mean
    97.6757
    Median
    99.54
    3rd Qu
    107.795
    Max
    203.75
    ,
    62 2020-03-11
    Min
    14.43
    1st Qu
    88.8525
    Mean
    96.2847
    Median
    99.13
    3rd Qu
    106.99
    Max
    189.71
    ,
    63 2020-03-12
    Min
    8.46
    1st Qu
    78.4825
    Mean
    89.2739
    Median
    90.89
    3rd Qu
    104.343
    Max
    160.86
    ,
    64 2020-03-13
    Min
    6.75
    1st Qu
    74.6525
    Mean
    88.9822
    Median
    89.76
    3rd Qu
    107.143
    Max
    152.82
    ,
    65 2020-03-14
    Min
    5.97
    1st Qu
    62.3375
    Median
    78.78
    Mean
    80.6979
    3rd Qu
    99.1675
    Max
    167.66
    ,
    66 2020-03-15
    Min
    5.85
    1st Qu
    47.8375
    Mean
    63.2225
    Median
    64.28
    3rd Qu
    75.6375
    Max
    129.47
    ,
    67 2020-03-16
    Min
    6.05
    1st Qu
    47.305
    Mean
    61.955
    Median
    62.62
    3rd Qu
    75.385
    Max
    144.31
    ,
    68 2020-03-17
    Min
    6.08
    1st Qu
    40.2075
    Mean
    56.7271
    Median
    56.74
    3rd Qu
    70.34
    Max
    149.79
    ,
    69 2020-03-18
    Min
    5.75
    1st Qu
    36.2875
    Mean
    52.8429
    Median
    53.18
    3rd Qu
    65.605
    Max
    146.36
    ,
    70 2020-03-19
    Min
    5.71
    1st Qu
    33.04
    Median
    50.56
    Mean
    51.3993
    3rd Qu
    63.275
    Max
    160.32
    ,
    71 2020-03-20
    Min
    5.26
    1st Qu
    31.4275
    Median
    48.41
    Mean
    51.5219
    3rd Qu
    64.6675
    Max
    161.59
    ,
    72 2020-03-21
    Min
    4.92
    1st Qu
    25.435
    Median
    40.3
    Mean
    44.5889
    3rd Qu
    55.3675
    Max
    152.12
    ,
    73 2020-03-22
    Min
    4.11
    1st Qu
    22.675
    Median
    36.07
    Mean
    39.8052
    3rd Qu
    47.6425
    Max
    143.15
    ,
    74 2020-03-23
    Min
    5.43
    1st Qu
    24.815
    Median
    37.56
    Mean
    41.4541
    3rd Qu
    49.8875
    Max
    147.59
    ,
    75 2020-03-24
    Min
    4.84
    1st Qu
    23.5225
    Median
    38.79
    Mean
    41.0819
    3rd Qu
    48.8075
    Max
    148.11
    ,
    76 2020-03-25
    Min
    4.88
    1st Qu
    22.9625
    Median
    36.91
    Mean
    40.815
    3rd Qu
    49.125
    Max
    153.53
    ,
    77 2020-03-26
    Min
    4.79
    1st Qu
    22.8425
    Median
    36.88
    Mean
    40.4594
    3rd Qu
    49.545
    Max
    125.86
    ,
    78 2020-03-27
    Min
    4.11
    1st Qu
    23.195
    Median
    37.97
    Mean
    41.5588
    3rd Qu
    53.4125
    Max
    132.86
    ,
    79 2020-03-28
    Min
    4.66
    1st Qu
    20.9825
    Median
    33.63
    Mean
    38.1246
    3rd Qu
    49.1825
    Max
    130.28
    ,
    80 2020-03-29
    Min
    3.98
    1st Qu
    18.9825
    Median
    29.68
    Mean
    34.3511
    3rd Qu
    41.435
    Max
    126.13
    ,
    81 2020-03-30
    Min
    5.07
    1st Qu
    22.09
    Median
    34.92
    Mean
    37.0765
    3rd Qu
    46.565
    Max
    122.07
    ,
    82 2020-03-31
    Min
    4.9
    1st Qu
    22.31
    Median
    35.44
    Mean
    37.7394
    3rd Qu
    47.7975
    Max
    116.37
    ,
    83 2020-04-01
    Min
    4.67
    1st Qu
    22.4225
    Median
    35.45
    Mean
    38.6266
    3rd Qu
    48.33
    Max
    123.01
    ,
    84 2020-04-02
    Min
    5.51
    1st Qu
    22.48
    Median
    35.78
    Mean
    38.5865
    3rd Qu
    47.92
    Max
    135.56
    ,
    85 2020-04-03
    Min
    4.72
    1st Qu
    22.5775
    Median
    36.35
    Mean
    39.0935
    3rd Qu
    51.325
    Max
    126.2
    ,
    86 2020-04-04
    Min
    4.42
    1st Qu
    19.8925
    Median
    33.85
    Mean
    37.0806
    3rd Qu
    48.3325
    Max
    116.05
    ,
    87 2020-04-05
    Min
    3.78
    1st Qu
    19.37
    Median
    33.36
    Mean
    36.4957
    3rd Qu
    47.73
    Max
    108.25
    ,
    88 2020-04-06
    Min
    5.45
    1st Qu
    23.39
    Median
    37.3
    Mean
    39.5495
    3rd Qu
    52.715
    Max
    103.3
    ,
    89 2020-04-07
    Min
    5.8
    1st Qu
    23.835
    Median
    38.13
    Mean
    40.279
    3rd Qu
    53.545
    Max
    101.08
    ,
    90 2020-04-08
    Min
    5.78
    1st Qu
    23.395
    Median
    38.93
    Mean
    40.7481
    3rd Qu
    55.3175
    Max
    102.94
    ,
    91 2020-04-09
    Min
    5.48
    1st Qu
    22.5525
    Median
    36.88
    Mean
    39.4362
    3rd Qu
    52.975
    Max
    104.48
    ,
    92 2020-04-10
    Min
    4.46
    1st Qu
    22.3675
    Median
    35.99
    Mean
    39.5669
    3rd Qu
    51.9925
    Max
    126.38
    ,
    93 2020-04-11
    Min
    4.91
    1st Qu
    20.94
    Median
    34.53
    Mean
    36.8363
    3rd Qu
    49.7825
    Max
    103.79
    ,
    94 2020-04-12
    Min
    4.13
    1st Qu
    18.385
    Median
    31.69
    Mean
    32.8423
    3rd Qu
    43.685
    Max
    87.95
    ,
    95 2020-04-13
    Min
    4.47
    1st Qu
    22.3575
    Median
    36.54
    Mean
    37.0427
    3rd Qu
    47.9125
    Max
    94.74
    ,
    96 2020-04-14
    Min
    6.53
    1st Qu
    23.535
    Median
    38.91
    Mean
    39.5543
    3rd Qu
    52.2575
    Max
    92.09
    
    Number of unique “country/region” values:
    In[]:=
    Length[Union[Normal[dsAppleMobility[Select[#["geo_type"]=="country/region"&],"region"]]]]
    Out[]=
    63
    Number of unique “city” values:
    In[]:=
    Length[Union[Normal[dsAppleMobility[Select[#["geo_type"]=="city"&],"region"]]]]
    Out[]=
    89
    All unique geo types:
    In[]:=
    lsGeoTypes=Union[Normal[dsAppleMobility[All,"geo_type"]]]
    Out[]=
    {city,country/region}
    All unique transportation types:
    In[]:=
    lsTransportationTypes=Union[Normal[dsAppleMobility[All,"transportation_type"]]]
    Out[]=
    {driving,transit,walking}

    Data Transformation

    It is better to have the data in long form (narrow form). For that I am using the package "DataReshape.m" [AAp1].
    In[]:=
    lsIDColumnNames={"geo_type","region","transportation_type"};​​dsAppleMobilityLongForm=ToLongForm[dsAppleMobility,lsIDColumnNames,Complement[Keys[dsAppleMobility〚1〛],lsIDColumnNames]];​​Dimensions[dsAppleMobilityLongForm]
    Remove the rows with “empty” values:
    Rename the column “Variable” to “Date” and add a related “DateObject” column:
    Add “day name” (“day of the week”) field:
    Here is sample of the transformed data:
    Here is a summary:
    Partition the data into geo types × transportation types:

    Basic Data Analysis

    We consider relative volume of directions requests for the last date only. (The queries can easily be adjusted for other dates.)
    Here we plot histograms and Pareto principle adherence:

    Heat-Map Plots

    We can visualize the data using heat-map plots. Here we use the package "HeatmapPlot.m" [AAp2].
    Remark: Using the contingency matrices prepared for the heat-map plots, we can do further analysis like finding correlations or nearest neighbors. (See below.)
    Cross tabulate dates with regions:
    Make a heat-map plot by sorting the columns of the cross-tabulation matrix (that correspond to countries):
    (We use Rasterize in order to reduce the size of the notebook.)
    Here we take closer look at one of the plots:

    Nearest Neighbors Graphs

    Graphs Overview

    Here we create nearest neighbor graphs of the contingency matrices computed above and plot clustered nodes:

    Closer Look into the Graphs

    Here we endow each nearest neighbors graph with appropriate vertex labels:
    Here we plot the graphs with clusters:
    Observation: From the community clusters of the nearest neighbor graphs (derived from the time series of the normalized driving directions request volume), we see that countries and cities are clustered in expected ways. For example, in the community graph plot corresponding to “{city, driving}” the cities Oslo, Copenhagen, Helsinki, Stockholm and Zurich are placed in the same cluster. In the graphs corresponding to “{city, transit}” and “{city, walking}”, the Japanese cities Tokyo, Osaka, Nagoya and Fukuoka are clustered together.

    Time Series Analysis

    Time series

    In this section, for each date we sum all cases over the region-transportation pairs, make a time series and plot them.
    Remark: In the plots, the Sundays are indicated with orange dashed lines.
    Here we make the time series:
    Here we plot them:
    Observation: In the time series plots, the Sundays are indicated with orange dashed lines. We can see that from Monday to Thursday people are more familiar with their trips than, say, on Fridays and Saturdays. We can also see that on Sundays people (on average) are more familiar with their trips or simply travel less.

    “Forecast”

    He we do a “forecast” for code-workflow demonstration purposes—the forecasts should not be taken seriously.
    Fit a time series model to the time series:
    Plot the data and forecast:

    References

    [APPL1] Apple Inc. 2020. Mobility Trends Reports. apple.com.
    [AA1] Antonov, Anton. 2020. "NY Times COVID-19 Data Visualization." SystemModeling at GitHub.
    [AAp1] Antonov, Anton. 2018. “Data Reshaping Mathematica Package.” MathematicaForPrediciton at GitHub.
    [AAp2] Antonov, Anton. 2018. “Heatmap Plot Mathematica Package.” MathematicaForPrediciton at GitHub.