Part 0

Install appropriate packages

packages = c('rgdal', 'spdep',  'tmap', 'tidyverse', 'sf','sp','gifski')
for (p in packages){
  if(!require(p, character.only = T)){
    install.packages(p)
  }
  library(p,character.only = T)
}
## Loading required package: rgdal
## Loading required package: sp
## rgdal: version: 1.5-17, (SVN revision 1070)
## Geospatial Data Abstraction Library extensions to R successfully loaded
## Loaded GDAL runtime: GDAL 3.0.4, released 2020/01/28
## Path to GDAL shared files: C:/Users/ahhli/OneDrive/Documents/R/win-library/4.0/rgdal/gdal
## GDAL binary built with GEOS: TRUE 
## Loaded PROJ runtime: Rel. 6.3.1, February 10th, 2020, [PJ_VERSION: 631]
## Path to PROJ shared files: C:/Users/ahhli/OneDrive/Documents/R/win-library/4.0/rgdal/proj
## Linking to sp version:1.4-4
## To mute warnings of possible GDAL/OSR exportToProj4() degradation,
## use options("rgdal_show_exportToProj4_warnings"="none") before loading rgdal.
## Loading required package: spdep
## Loading required package: spData
## To access larger datasets in this package, install the spDataLarge
## package with: `install.packages('spDataLarge',
## repos='https://nowosad.github.io/drat/', type='source')`
## Loading required package: sf
## Linking to GEOS 3.8.0, GDAL 3.0.4, PROJ 6.3.1
## Loading required package: tmap
## Loading required package: tidyverse
## -- Attaching packages --------------------------------------- tidyverse 1.3.0 --
## v ggplot2 3.3.2     v purrr   0.3.4
## v tibble  3.0.3     v dplyr   1.0.2
## v tidyr   1.1.2     v stringr 1.4.0
## v readr   1.4.0     v forcats 0.5.0
## -- Conflicts ------------------------------------------ tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag()    masks stats::lag()
## Loading required package: gifski

Load data

muni <- readOGR(dsn = "data/geospatial", layer = "municipalities_COVID")
## Warning in OGRSpatialRef(dsn, layer, morphFromESRI = morphFromESRI, dumpSRS =
## dumpSRS, : Discarded datum International_Terrestrial_Reference_Frame_2008 in CRS
## definition: +proj=lcc +lat_0=12 +lon_0=-102 +lat_1=17.5 +lat_2=29.5 +x_0=2500000
## +y_0=0 +ellps=GRS80 +units=m +no_defs
## OGR data source with driver: ESRI Shapefile 
## Source: "C:\Users\ahhli\OneDrive\Desktop\Geospatial\Take-home-Ex02\Take-Home-Ex02\data\geospatial", layer: "municipalities_COVID"
## with 2465 features
## It has 198 fields

We can look at each attribute and some of its corresponding values below to better understand the data.

head(muni@data)
##   CVEGEO CVE_ENT CVE_MUN               NOMGEO Pop2010 Pop2020 new1 new2 new3
## 0  01001      01     001       Aguascalientes  797010  961977    0    0    0
## 1  01002      01     002             Asientos   45492   50864    0    0    0
## 2  01003      01     003             Calvillo   54136   60760    0    0    0
## 3  01004      01     004               Cosío   15042   16918    0    0    0
## 4  01005      01     005        Jesús María   99590  130184    0    0    0
## 5  01006      01     006 Pabellón de Arteaga   41862   50032    0    0    0
##   new4 new5 new6 new7 new8 new9 new10 new11 new12 new13 new14 new15 new16 new17
## 0    0    0    0    0    0    0     0     1     7    30     8    10    51    60
## 1    0    0    0    0    0    0     0     0     1     0     0     0     0     0
## 2    0    0    0    0    0    0     0     0     0     0     0     0     0     8
## 3    0    0    0    0    0    0     0     0     0     0     0     0     0     0
## 4    0    0    0    0    0    0     0     0     0     1     0     0     6     3
## 5    0    0    0    0    0    0     0     0     0     4     1     0     0     0
##   new18 new19 new20 new21 new22 new23 new24 new25 new26 new27 new28 new29 new30
## 0    87   101   101    99   185   257   312   280   258   234   295   307   267
## 1     1     0     0     5     2     1     8     6     4     9    11     6     7
## 2     1     1     1     0     0     3     3     8    11     8    20    35    13
## 3     0     0     6     7     3     7     6    12     1     0     2    10     9
## 4     3     4     5     5     6     5    11    10    15    14    15    13    10
## 5     6     3     2    14     6    17     8    19    13     7     8    21    14
##   new31 new32 cumul1 cumul2 cumul3 cumul4 cumul5 cumul6 cumul7 cumul8 cumul9
## 0   219    23      0      0      0      0      0      0      0      0      0
## 1    11     0      0      0      0      0      0      0      0      0      0
## 2    13     3      0      0      0      0      0      0      0      0      0
## 3     4     0      0      0      0      0      0      0      0      0      0
## 4    15     2      0      0      0      0      0      0      0      0      0
## 5    19     0      0      0      0      0      0      0      0      0      0
##   cumul10 cumul11 cumul12 cumul13 cumul14 cumul15 cumul16 cumul17 cumul18
## 0       0       1       8      38      46      56     107     167     254
## 1       0       0       1       1       1       1       1       1       2
## 2       0       0       0       0       0       0       0       8       9
## 3       0       0       0       0       0       0       0       0       0
## 4       0       0       0       1       1       1       7      10      13
## 5       0       0       0       4       5       5       5       5      11
##   cumul19 cumul20 cumul21 cumul22 cumul23 cumul24 cumul25 cumul26 cumul27
## 0     355     456     555     740     997    1309    1589    1847    2081
## 1       2       2       7       9      10      18      24      28      37
## 2      10      11      11      11      14      17      25      36      44
## 3       0       6      13      16      23      29      41      42      42
## 4      17      22      27      33      38      49      59      74      88
## 5      14      16      30      36      53      61      80      93     100
##   cumul28 cumul29 cumul30 cumul31 cumul32 activ1 activ2 activ3 activ4 activ5
## 0    2376    2683    2950    3169    3192      0      0      0      0      0
## 1      48      54      61      72      72      0      0      0      0      0
## 2      64      99     112     125     128      0      0      0      0      0
## 3      44      54      63      67      67      0      0      0      0      0
## 4     103     116     126     141     143      0      0      0      0      0
## 5     108     129     143     162     162      0      0      0      0      0
##   activ6 activ7 activ8 activ9 activ10 activ11 activ12 activ13 activ14 activ15
## 0      0      0      0      0       1       4      16      45      53      75
## 1      0      0      0      0       0       0       1       1       1       1
## 2      0      0      0      0       0       0       0       0       0       0
## 3      0      0      0      0       0       0       0       0       0       0
## 4      0      0      0      0       0       0       0       1       1       3
## 5      0      0      0      0       0       0       0       5       5       5
##   activ16 activ17 activ18 activ19 activ20 activ21 activ22 activ23 activ24
## 0     139     203     309     393     500     622     848    1133    1424
## 1       1       1       2       2       4       9      10      14      19
## 2       0       9       9      11      11      11      12      15      18
## 3       0       0       0       1       7      14      18      27      34
## 4       7      12      14      19      23      28      34      44      53
## 5       5       5      13      14      22      34      41      60      70
##   activ25 activ26 activ27 activ28 activ29 activ30 activ31 activ32 death1 death2
## 0    1713    1972    2248    2544    2845    3079    3189    3192      0      0
## 1      27      31      41      51      56      70      72      72      0      0
## 2      28      39      53      90     108     124     127     128      0      0
## 3      42      42      43      50      56      66      67      67      0      0
## 4      69      83      96     109     122     135     143     143      0      0
## 5      88      95     104     119     135     148     162     162      0      0
##   death3 death4 death5 death6 death7 death8 death9 death10 death11 death12
## 0      0      0      0      0      0      0      0       0       0       0
## 1      0      0      0      0      0      0      0       0       0       0
## 2      0      0      0      0      0      0      0       0       0       0
## 3      0      0      0      0      0      0      0       0       0       0
## 4      0      0      0      0      0      0      0       0       0       0
## 5      0      0      0      0      0      0      0       0       0       0
##   death13 death14 death15 death16 death17 death18 death19 death20 death21
## 0       0       0       1       2       2       3       7       6       4
## 1       0       0       0       0       0       0       0       0       0
## 2       0       0       0       0       0       0       0       0       0
## 3       0       0       0       0       0       0       0       0       0
## 4       0       0       0       0       0       0       0       0       2
## 5       0       0       0       0       0       0       0       0       1
##   death22 death23 death24 death25 death26 death27 death28 death29 death30
## 0      17      18      27      25      24      19      19      19      20
## 1       0       0       0       0       2       0       2       2       0
## 2       0       0       0       0       1       0       0       0       1
## 3       0       0       0       0       0       0       0       0       0
## 4       0       0       0       0       0       0       0       1       3
## 5       1       0       1       1       1       0       1       0       1
##   death31 death32 actvrt1 actvrt2 actvrt3 actvrt4 actvrt5 actvrt6 actvrt7
## 0      13       7       0       0       0       0       0       0       0
## 1       0       0       0       0       0       0       0       0       0
## 2       0       0       0       0       0       0       0       0       0
## 3       0       0       0       0       0       0       0       0       0
## 4       0       0       0       0       0       0       0       0       0
## 5       0       0       0       0       0       0       0       0       0
##   actvrt8 actvrt9   actvr10   actvr11  actvr12   actvr13   actvr14  actvr15
## 0       0       0 0.1039526 0.4158104 1.663241 4.5739139 5.0936769 6.133203
## 1       0       0 0.0000000 0.0000000 1.966027 1.9660271 1.9660271 0.000000
## 2       0       0 0.0000000 0.0000000 0.000000 0.0000000 0.0000000 0.000000
## 3       0       0 0.0000000 0.0000000 0.000000 0.0000000 0.0000000 0.000000
## 4       0       0 0.0000000 0.0000000 0.000000 0.7681436 0.7681436 2.304431
## 5       0       0 0.0000000 0.0000000 0.000000 9.9936041 9.9936041 9.993604
##    actvr16   actvr17   actvr18   actvr19   actvr20   actvr21   actvr22
## 0 9.771543 15.592888 24.324906 26.403958 30.873919 32.537160  47.29843
## 1 0.000000  0.000000  1.966027  1.966027  5.898081 13.762189  15.72822
## 2 0.000000 14.812377 14.812377 18.104016  3.291639  3.291639   1.64582
## 3 0.000000  0.000000  0.000000  5.910864 41.376049 82.752098 100.48469
## 4 4.608861  8.449579  8.449579  9.217723  8.449579 10.754010  11.52215
## 5 0.000000  0.000000 15.989767 17.988487 33.978254 41.973137  53.96546
##      actvr23   actvr24   actvr25  actvr26  actvr27   actvr28   actvr29
## 0  65.801989  83.36998  89.91899 87.21622 85.65693  86.38460  90.75061
## 1  19.660271  19.66027  33.42246 33.42246 43.25260  47.18465  49.15068
## 2   6.583278  11.52074  26.33311 39.49967 57.60369 102.04082 113.56155
## 3 118.217283 118.21728 141.86074 88.66296 53.19778  47.28691  82.75210
## 4  16.131015  19.20359  26.88502 29.95760 33.03017  30.72574  29.95760
## 5  75.951391  71.95395  93.93988 69.95523 67.95651  61.96035  79.94883
##     actvr30   actvr31  actvr32 dethrt1 dethrt2 dethrt3 dethrt4 dethrt5 dethrt6
## 0  86.38460  67.04942 36.07155       0       0       0       0       0       0
## 1  57.01478  41.28657 31.45643       0       0       0       0       0       0
## 2 116.85319  60.89533 32.91639       0       0       0       0       0       0
## 3 135.94988 100.48469 65.01951       0       0       0       0       0       0
## 4  29.95760  26.11688 16.13101       0       0       0       0       0       0
## 5  87.94372  85.94500 53.96546       0       0       0       0       0       0
##   dethrt7 dethrt8 dethrt9 dthrt10 dthrt11 dthrt12 dthrt13 dthrt14   dthrt15
## 0       0       0       0       0       0       0       0       0 0.1039526
## 1       0       0       0       0       0       0       0       0 0.0000000
## 2       0       0       0       0       0       0       0       0 0.0000000
## 3       0       0       0       0       0       0       0       0 0.0000000
## 4       0       0       0       0       0       0       0       0 0.0000000
## 5       0       0       0       0       0       0       0       0 0.0000000
##     dthrt16   dthrt17   dthrt18   dthrt19   dthrt20   dthrt21  dthrt22  dthrt23
## 0 0.2079052 0.2079052 0.3118578 0.7276681 0.6237155 0.4158104 1.767194 1.871147
## 1 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.000000 0.000000
## 2 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.000000 0.000000
## 3 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.000000 0.000000
## 4 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 1.5362871 0.000000 0.000000
## 5 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 1.9987208 1.998721 0.000000
##    dthrt24  dthrt25  dthrt26  dthrt27  dthrt28   dthrt29  dthrt30  dthrt31
## 0 2.806720 2.598815 2.494862 1.975099 1.975099 1.9750992 2.079052 1.351384
## 1 0.000000 0.000000 3.932054 0.000000 3.932054 3.9320541 0.000000 0.000000
## 2 0.000000 0.000000 1.645820 0.000000 0.000000 0.0000000 1.645820 0.000000
## 3 0.000000 0.000000 0.000000 0.000000 0.000000 0.0000000 0.000000 0.000000
## 4 0.000000 0.000000 0.000000 0.000000 0.000000 0.7681436 2.304431 0.000000
## 5 1.998721 1.998721 1.998721 0.000000 1.998721 0.0000000 1.998721 0.000000
##     dthrt32
## 0 0.7276681
## 1 0.0000000
## 2 0.0000000
## 3 0.0000000
## 4 0.0000000
## 5 0.0000000

Part 1

1.1 Extract municipalities located with the study area

As mentioned in the task description, there is a need for data wrangling in order to specifically analyse the spatio-temporal patterns of COVID-19 cases at following areas: 1. Mexico City (9) 2. Mexico State (15) 3. Morelos State (17) Using the attribute “CVE_ENT”, we extract the relevant municipalities.

mexico_city <- muni[muni@data$CVE_ENT == "09",]
mexico_state <- muni[muni@data$CVE_ENT == "15",]
morelos_state <- muni[muni@data$CVE_ENT == "17",]

1.2 Calculate the COVID-19 rate (i.e. cases per 10000 population) from e-week 13 until e-week 32.

In order to calculate the rate of COVID-19, we look at the attributes “cumul” and “Pop2020” in our calculations.

for (i in c(13:32)) {
  mexico_city[[paste0("covidrate_wk",i)]] <- mexico_city[[paste0("cumul",i)]] / (mexico_city$Pop2020 / 10000)
  mexico_state[[paste0("covidrate_wk",i)]] <- mexico_state[[paste0("cumul",i)]] / (mexico_state$Pop2020 / 10000)
  morelos_state[[paste0("covidrate_wk",i)]] <- morelos_state[[paste0("cumul",i)]] / (morelos_state$Pop2020 / 10000)
}
mexico_city
## class       : SpatialPolygonsDataFrame 
## features    : 16 
## extent      : 2776218, 2820850, 786788.9, 846749.5  (xmin, xmax, ymin, ymax)
## crs         : +proj=lcc +lat_0=12 +lon_0=-102 +lat_1=17.5 +lat_2=29.5 +x_0=2500000 +y_0=0 +ellps=GRS80 +units=m +no_defs 
## variables   : 218
## names       : CVEGEO, CVE_ENT, CVE_MUN,           NOMGEO, Pop2010, Pop2020, new1, new2, new3, new4, new5, new6, new7, new8, new9, ... 
## min values  :  09002,      09,     002, Álvaro Obregón,  130582,  139371,    0,    0,    0,    0,    0,    0,    0,    0,    0, ... 
## max values  :  09017,      09,     017,       Xochimilco, 1815786, 1815551,    0,    0,    0,    0,    0,    0,    0,    0,    1, ...

Part 2

2.1 Data wrangling and preparation for spatio-temporal pattern analysis

Firstly, we will have to convert the 3 spatial polygon dataframes into sf objects for visualisation purpose.

mexico_city_sf <- st_as_sf(mexico_city)
mexico_state_sf <- st_as_sf(mexico_state)
morelos_state_sf <- st_as_sf(morelos_state)

Next, as the sf object sizes are big, we should select the variables that we need and use them for the subsequent steps. The variables that are relevant in this part of the study are “NOMGEO” and the previously processed variable, “covidrate_wkX” where 13 <= X <= 32. This step will be repeated for all 3 study areas.

variables = c("NOMGEO")
for (i in c(13:32)) {
  variables <- c(variables, paste0("covidrate_wk",i))
}

mexico_city_sf <- subset(mexico_city_sf, select=variables)
mexico_state_sf <- subset(mexico_state_sf, select=variables)
morelos_state_sf <- subset(morelos_state_sf, select=variables)

# Bind sf objects to form central mexico sf 
central_mexico_sf <- rbind(mexico_city_sf,mexico_state_sf,morelos_state_sf)
central_mexico_sf
## Simple feature collection with 176 features and 21 fields
## geometry type:  GEOMETRY
## dimension:      XY
## bbox:           xmin: 2645804 ymin: 707708.1 xmax: 2855437 ymax: 921773.9
## projected CRS:  MEXICO_ITRF_2008_LCC
## First 10 features:
##                     NOMGEO covidrate_wk13 covidrate_wk14 covidrate_wk15
## 270           Azcapotzalco     0.46518347     1.12623365      2.1300506
## 271              Coyoacán     0.40196028     0.70745009      1.7203900
## 272  Cuajimalpa de Morelos     3.30315451     3.75358467      4.6544450
## 273      Gustavo A. Madero     0.23789962     0.81565583      1.6398081
## 274              Iztacalco     0.27931471     0.68559066      1.6504960
## 275             Iztapalapa     0.22582676     0.55079698      1.2392932
## 276 La Magdalena Contreras     0.61187777     1.10137999      1.8356333
## 277             Milpa Alta     0.00000000     0.07175094      1.6502716
## 278       Ã\201lvaro Obregón     0.74119467     1.19120573      1.9324004
## 279               Tláhuac     0.08183619     0.30006601      0.8183619
##     covidrate_wk16 covidrate_wk17 covidrate_wk18 covidrate_wk19 covidrate_wk20
## 270       3.819401       6.218768       9.572986       15.05725       22.79399
## 271       3.424702       6.029404       8.907440       13.36116       18.49017
## 272       6.105831       7.857504      10.109655       13.01243       16.16544
## 273       3.373077       6.236369       9.405531       14.04457       19.79665
## 274       4.773742       8.709541      14.016520       20.46615       28.56628
## 275       2.897192       5.843956       9.660979       14.41436       19.73506
## 276       3.385724       6.893823       8.974207       11.99280       17.41812
## 277       4.233305       9.829879      14.852444       21.59703       30.13539
## 278       3.573617       5.453075       8.060492       11.21057       15.47244
## 279       2.155020       4.773778       8.456406       13.99399       22.25944
##     covidrate_wk21 covidrate_wk22 covidrate_wk23 covidrate_wk24 covidrate_wk25
## 270       31.02039       38.92851       47.47320       55.06303       63.50978
## 271       23.98899       30.00232       36.25682       41.06426       47.20622
## 272       20.71979       28.67739       35.73413       42.59067       49.59737
## 273       26.40686       32.65172       39.71224       45.59176       50.78307
## 274       36.31091       43.31917       50.50518       56.09147       62.31257
## 275       25.66163       30.47009       35.33913       39.84465       43.95911
## 276       23.29215       29.08459       34.22436       39.20097       46.58429
## 277       44.12683       55.82223       68.95265       84.95311       97.15077
## 278       20.56815       25.69034       30.75958       36.82149       42.57899
## 279       31.86155       38.21750       46.48295       52.94801       60.55878
##     covidrate_wk26 covidrate_wk27 covidrate_wk28 covidrate_wk29 covidrate_wk30
## 270       71.54032       79.27706       86.64654       93.99154      102.12001
## 271       51.57954       57.72150       62.75404       70.63246       77.49794
## 272       55.90339       64.31142       72.26902       80.82719       91.83771
## 273       55.24369       60.11214       64.46230       69.77256       75.40568
## 274       67.54338       71.73310       76.10056       80.82352       86.73991
## 275       47.62191       51.81898       55.50932       59.60725       63.61705
## 276       53.88604       62.37074       71.71207       85.78526       95.86085
## 277      106.98065      119.60881      130.44321      145.08040      159.21533
## 278       47.43646       52.57188       58.11760       65.58249       72.09442
## 279       68.11499       76.16221       84.67317       94.24801      103.14087
##     covidrate_wk31 covidrate_wk32                       geometry
## 270      108.75500      109.34260 POLYGON ((2794860 837218.4,...
## 271       83.86499       84.34735 POLYGON ((2799635 820691.6,...
## 272       97.54315       97.89349 POLYGON ((2787230 825329.3,...
## 273       79.69637       80.19766 POLYGON ((2802176 843326.7,...
## 274       91.71680       93.29111 POLYGON ((2808291 828067.6,...
## 275       67.03199       67.77557 POLYGON ((2812453 823708.1,...
## 276      107.16019      107.64970 POLYGON ((2792518 818323.1,...
## 277      169.61922      170.40848 POLYGON ((2814877 806710.5,...
## 278       77.71956       78.54016 POLYGON ((2794396 824857.6,...
## 279      110.91531      111.95190 POLYGON ((2816579 817396, 2...

Before we proceed further, there are a couple of checks required for central mexico simple feature dataframe that needs to be done before we begin utilising it in the subsequent steps.

  1. Check for NA values in the central mexico simple feature dataframe.
  2. Check for invalid gemoetries in the central mexico simple feature dataframe.
# 1. NA check 
central_mexico_sf[rowSums(is.na(central_mexico_sf))!=0,]
## Simple feature collection with 0 features and 21 fields
## bbox:           xmin: NA ymin: NA xmax: NA ymax: NA
## projected CRS:  MEXICO_ITRF_2008_LCC
##  [1] NOMGEO         covidrate_wk13 covidrate_wk14 covidrate_wk15 covidrate_wk16
##  [6] covidrate_wk17 covidrate_wk18 covidrate_wk19 covidrate_wk20 covidrate_wk21
## [11] covidrate_wk22 covidrate_wk23 covidrate_wk24 covidrate_wk25 covidrate_wk26
## [16] covidrate_wk27 covidrate_wk28 covidrate_wk29 covidrate_wk30 covidrate_wk31
## [21] covidrate_wk32 geometry      
## <0 rows> (or 0-length row.names)

As seen in the output above, there’s no NA value in central_mexico_sf.

# 2. Validty Check 
test <- st_is_valid(central_mexico_sf)
length(which(test == FALSE))
## [1] 0

As seen in the output above, there’s no invalid geometries in central_mexico_sf.

2.2 Plotting of animated tmap to show gradual change in COVID-19 rates from e-week 13 to e-week 32

Note: the animation that is functioning properly is stored in the project directory folder. Please refer to the animation in that folder instead of the individual frames below.

central_mexico_sf_munis <- central_mexico_sf$NOMGEO

# Check that municipalities are distinct in central_mexico_sf_munis
if(length(central_mexico_sf_munis) != length(unique(central_mexico_sf_munis))){
  central_mexico_sf_munis <- unique(central_mexico_sf_munis)
}
# Create separate df to store relevant variables that will be required in tmap 
central_mexico_df <- data.frame(matrix(ncol=0,nrow=0))

for (muni in central_mexico_sf_munis) {
  # keep geometry attribute in order to convert the df to sf later on. 
  geometry <- subset(central_mexico_sf, NOMGEO == muni)$geometry
  for (i in c(13:32)) {
      covidrate_wk <- subset(central_mexico_sf, NOMGEO == muni)[[paste0("covidrate_wk",i)]]
      central_mexico_df <- rbind(central_mexico_df, data.frame(muni, geometry,covidrate_wk, i))
  }
}

# typeof(central_mexico_df)
central_mexico_sf_final <- st_as_sf(central_mexico_df)
typeof(central_mexico_sf_final)
## [1] "list"
tmap_central_mexico <- tm_shape(central_mexico_sf_final) +
    tm_fill("covidrate_wk", 
            style="fisher") +
    tm_borders() +
    tm_facets("i", nrow=1, ncol=1)
    tm_layout(
      title = "i",
      title.position = c("right","top"))
## $tm_layout
## $tm_layout$title
## [1] "i"
## 
## $tm_layout$title.position
## [1] "right" "top"  
## 
## $tm_layout$style
## [1] NA
## 
## 
## attr(,"class")
## [1] "tm"
tmap_central_mexico

## ========

## ====

## ====

## ====

## ====

## ====

## ====

## ====

## ====

## ====

## ====

## ====

## ====

## ====

## ====

## ====

## ====

## ====

## ====

2.3 Analysis of animated tmap

Based on the legend used, darker shades of yellow represent relatively higher level of COVID-19 cases for the particular week, whereas lighter shades represent relatively lower level of COVID-19 cases.

The week number is clearly shown at the top of the map.

As you can observe from the animation, there was no difference in yellow shades across all municipalities from e-week 13 to e-week 16.

However, from e-week 17 onwards, the first municipality located at mexico city was first spotted with darker shade of yellow, meaning that particular city was the first city to experience higher COVID-19 cases as compared to the rest.

Gradually as time passes, we can infer that more COVID-19 cases spread among the neighbouring municipalities as the yellow shades at mexico city become darker and those at mexico state as well as marelos city also experience gradual increase in yellow shades.

By the time it reaches e-week32, there is only a few municipalities left that remain at the lowest range of COVID-19 weekly rate, especially those at the extreme left boundary of Central Mexico.

animated_tmap <- tmap_animation(tmap_central_mexico, filename = "animation.gif", width = NA, height = NA,delay = 40)
## Creating frames
## ========
## ====
## ====
## ====
## ====
## ====
## ====
## ====
## ====
## ====
## ====
## ====
## ====
## ====
## ====
## ====
## ====
## ====
## ====
## 
## Creating animation
## 
Frame 1 (5%)
Frame 2 (10%)
Frame 3 (15%)
Frame 4 (20%)
Frame 5 (25%)
Frame 6 (30%)
Frame 7 (35%)
Frame 8 (40%)
Frame 9 (45%)
Frame 10 (50%)
Frame 11 (55%)
Frame 12 (60%)
Frame 13 (65%)
Frame 14 (70%)
Frame 15 (75%)
Frame 16 (80%)
Frame 17 (85%)
Frame 18 (90%)
Frame 19 (95%)
Frame 20 (100%)
## Finalizing encoding... done!
## Animation saved to C:\Users\ahhli\OneDrive\Desktop\Geospatial\Take-home-Ex02\Take-Home-Ex02\animation.gif

Part 3: Local Moran’s I Analysis

3.1 Derive spatial weight matrix

# Convert sf object of central mexico to spatial object 
central_mexico <- as_Spatial(central_mexico_sf)
## Warning in showSRID(uprojargs, format = "PROJ", multiline = "NO", prefer_proj =
## prefer_proj): Discarded datum Unknown based on GRS80 ellipsoid in CRS definition
## Warning in showSRID(SRS_string, format = "PROJ", multiline = "NO", prefer_proj =
## prefer_proj): Discarded datum International Terrestrial Reference Frame 2008 in
## CRS definition
wm_q <- poly2nb(central_mexico, queen=TRUE)
summary(wm_q)
## Neighbour list object:
## Number of regions: 176 
## Number of nonzero links: 962 
## Percentage nonzero weights: 3.10563 
## Average number of links: 5.465909 
## Link number distribution:
## 
##  1  2  3  4  5  6  7  8  9 10 11 14 
##  3  3 18 41 31 31 22 13  9  3  1  1 
## 3 least connected regions:
## 721 739 765 with 1 link
## 1 most connected region:
## 761 with 14 links
# central_mexico@polygons[[1]]

The summary above shows that there are 176 area units in Central Mexico. The most connected area unit has 14 neighbours. There are 3 area units with only one neighbour.

Let’s plot Queen contiguity based neighbours maps.

plot(central_mexico, border="lightgrey")
plot(wm_q, coordinates(central_mexico), pch = 19, cex = 0.6, add = TRUE, col= "red")

rswm_q <- nb2listw(wm_q, zero.policy = TRUE)
summary(rswm_q)
## Characteristics of weights list object:
## Neighbour list object:
## Number of regions: 176 
## Number of nonzero links: 962 
## Percentage nonzero weights: 3.10563 
## Average number of links: 5.465909 
## Link number distribution:
## 
##  1  2  3  4  5  6  7  8  9 10 11 14 
##  3  3 18 41 31 31 22 13  9  3  1  1 
## 3 least connected regions:
## 721 739 765 with 1 link
## 1 most connected region:
## 761 with 14 links
## 
## Weights style: W 
## Weights constants summary:
##     n    nn  S0       S1      S2
## W 176 30976 176 71.10695 731.679
fips <- order(central_mexico$NOMGEO)
localMI <- localmoran(central_mexico@data[["covidrate_wk13"]], rswm_q)
localMI_13 <- localmoran(central_mexico@data[["covidrate_wk13"]], rswm_q)
head(localMI_13)
##              Ii         E.Ii     Var.Ii       Z.Ii    Pr(z > 0)
## 270  1.42938461 -0.005714286 0.15624522  3.6306005 0.0001413813
## 271  0.52791359 -0.005714286 0.15624522  1.3500042 0.0885073115
## 272 21.14786143 -0.005714286 0.19615364 47.7623404 0.0000000000
## 273  0.06784766 -0.005714286 0.09638259  0.2369485 0.4063483824
## 274  0.17785066 -0.005714286 0.15624522  0.4643938 0.3211828265
## 275  0.04471045 -0.005714286 0.09638259  0.1624218 0.4354868483
for(i in 13:32){
  weekly_rate<-paste("covidrate_wk",i, sep="")
  localMIObj <- paste("localMI_week", i, sep="")
  # weekly_rate
  # localMIObj
  localMIObj <- localmoran(central_mexico[[weekly_rate]], rswm_q)
  localMIObj_name <- paste0(i,"_localMI")
  # localMIObj_name
  localMIObj_name <- cbind(central_mexico,localMIObj)
  # Mapping Local Moran's I 
  
  localMI.map_name<- paste("localMIPlot_week", i,sep="")
  localMI.map <- tm_shape(localMIObj_name) +
  tm_fill(col = "Ii", 
          style = "pretty",
          palette = "RdBu",
          title = "local moran statistics") +
  tm_borders(alpha = 0.5)
  assign(localMI.map_name,localMI.map)

# localMIPlot_week18

  # Mapping Local Moran's I p-values
  pvalue.map_name<- paste("pvaluePlot_week", i,sep="")
  pvalue.map <- tm_shape(localMIObj_name) +
    tm_fill(col = "Pr.z...0.", 
            breaks=c(-Inf, 0.001, 0.01, 0.05, 0.1, Inf),
            palette="-Blues", 
            title = "local Moran's I p-values") +
    tm_borders(alpha = 0.5)
  assign(pvalue.map_name,pvalue.map)
  
  
}

Below are the LocalMI plot and Pvalue plot for e-week 13

tmap_arrange(localMIPlot_week13, pvaluePlot_week13,localMIPlot_week14, pvaluePlot_week14,asp=2, ncol=2)
## Warning in sp::proj4string(obj): CRS object has comment, which is lost in output
## Variable(s) "Ii" contains positive and negative values, so midpoint is set to 0. Set midpoint = NA to show the full spectrum of the color palette.
## Warning in sp::proj4string(obj): CRS object has comment, which is lost in output

## Warning in sp::proj4string(obj): CRS object has comment, which is lost in output
## Variable(s) "Ii" contains positive and negative values, so midpoint is set to 0. Set midpoint = NA to show the full spectrum of the color palette.
## Warning in sp::proj4string(obj): CRS object has comment, which is lost in output

tmap_arrange(localMIPlot_week15, pvaluePlot_week15,localMIPlot_week16, pvaluePlot_week16, asp=2, ncol=2)
## Warning in sp::proj4string(obj): CRS object has comment, which is lost in output
## Variable(s) "Ii" contains positive and negative values, so midpoint is set to 0. Set midpoint = NA to show the full spectrum of the color palette.
## Warning in sp::proj4string(obj): CRS object has comment, which is lost in output

## Warning in sp::proj4string(obj): CRS object has comment, which is lost in output
## Variable(s) "Ii" contains positive and negative values, so midpoint is set to 0. Set midpoint = NA to show the full spectrum of the color palette.
## Warning in sp::proj4string(obj): CRS object has comment, which is lost in output

tmap_arrange(localMIPlot_week17, pvaluePlot_week17,localMIPlot_week18, pvaluePlot_week18, asp=2, ncol=2)
## Warning in sp::proj4string(obj): CRS object has comment, which is lost in output
## Variable(s) "Ii" contains positive and negative values, so midpoint is set to 0. Set midpoint = NA to show the full spectrum of the color palette.
## Warning in sp::proj4string(obj): CRS object has comment, which is lost in output

## Warning in sp::proj4string(obj): CRS object has comment, which is lost in output
## Variable(s) "Ii" contains positive and negative values, so midpoint is set to 0. Set midpoint = NA to show the full spectrum of the color palette.
## Warning in sp::proj4string(obj): CRS object has comment, which is lost in output

tmap_arrange(localMIPlot_week19, pvaluePlot_week19,localMIPlot_week20, pvaluePlot_week20, asp=2, ncol=2)
## Warning in sp::proj4string(obj): CRS object has comment, which is lost in output
## Variable(s) "Ii" contains positive and negative values, so midpoint is set to 0. Set midpoint = NA to show the full spectrum of the color palette.
## Warning in sp::proj4string(obj): CRS object has comment, which is lost in output

## Warning in sp::proj4string(obj): CRS object has comment, which is lost in output
## Variable(s) "Ii" contains positive and negative values, so midpoint is set to 0. Set midpoint = NA to show the full spectrum of the color palette.
## Warning in sp::proj4string(obj): CRS object has comment, which is lost in output

tmap_arrange(localMIPlot_week21, pvaluePlot_week21,localMIPlot_week22, pvaluePlot_week22, asp=2, ncol=2)
## Warning in sp::proj4string(obj): CRS object has comment, which is lost in output
## Variable(s) "Ii" contains positive and negative values, so midpoint is set to 0. Set midpoint = NA to show the full spectrum of the color palette.
## Warning in sp::proj4string(obj): CRS object has comment, which is lost in output

## Warning in sp::proj4string(obj): CRS object has comment, which is lost in output
## Variable(s) "Ii" contains positive and negative values, so midpoint is set to 0. Set midpoint = NA to show the full spectrum of the color palette.
## Warning in sp::proj4string(obj): CRS object has comment, which is lost in output

tmap_arrange(localMIPlot_week23, pvaluePlot_week23,localMIPlot_week24, pvaluePlot_week24, asp=2, ncol=2)
## Warning in sp::proj4string(obj): CRS object has comment, which is lost in output
## Variable(s) "Ii" contains positive and negative values, so midpoint is set to 0. Set midpoint = NA to show the full spectrum of the color palette.
## Warning in sp::proj4string(obj): CRS object has comment, which is lost in output

## Warning in sp::proj4string(obj): CRS object has comment, which is lost in output
## Variable(s) "Ii" contains positive and negative values, so midpoint is set to 0. Set midpoint = NA to show the full spectrum of the color palette.
## Warning in sp::proj4string(obj): CRS object has comment, which is lost in output

tmap_arrange(localMIPlot_week25, pvaluePlot_week25,localMIPlot_week26, pvaluePlot_week26, asp=2, ncol=2)
## Warning in sp::proj4string(obj): CRS object has comment, which is lost in output
## Variable(s) "Ii" contains positive and negative values, so midpoint is set to 0. Set midpoint = NA to show the full spectrum of the color palette.
## Warning in sp::proj4string(obj): CRS object has comment, which is lost in output

## Warning in sp::proj4string(obj): CRS object has comment, which is lost in output
## Variable(s) "Ii" contains positive and negative values, so midpoint is set to 0. Set midpoint = NA to show the full spectrum of the color palette.
## Warning in sp::proj4string(obj): CRS object has comment, which is lost in output

tmap_arrange(localMIPlot_week27, pvaluePlot_week27,localMIPlot_week28, pvaluePlot_week28, asp=2, ncol=2)
## Warning in sp::proj4string(obj): CRS object has comment, which is lost in output
## Variable(s) "Ii" contains positive and negative values, so midpoint is set to 0. Set midpoint = NA to show the full spectrum of the color palette.
## Warning in sp::proj4string(obj): CRS object has comment, which is lost in output

## Warning in sp::proj4string(obj): CRS object has comment, which is lost in output
## Variable(s) "Ii" contains positive and negative values, so midpoint is set to 0. Set midpoint = NA to show the full spectrum of the color palette.
## Warning in sp::proj4string(obj): CRS object has comment, which is lost in output

tmap_arrange(localMIPlot_week29, pvaluePlot_week29,localMIPlot_week30, pvaluePlot_week30, asp=2, ncol=2)
## Warning in sp::proj4string(obj): CRS object has comment, which is lost in output
## Variable(s) "Ii" contains positive and negative values, so midpoint is set to 0. Set midpoint = NA to show the full spectrum of the color palette.
## Warning in sp::proj4string(obj): CRS object has comment, which is lost in output

## Warning in sp::proj4string(obj): CRS object has comment, which is lost in output
## Variable(s) "Ii" contains positive and negative values, so midpoint is set to 0. Set midpoint = NA to show the full spectrum of the color palette.
## Warning in sp::proj4string(obj): CRS object has comment, which is lost in output

tmap_arrange(localMIPlot_week31, pvaluePlot_week31,localMIPlot_week32, pvaluePlot_week32, asp=2, ncol=2)
## Warning in sp::proj4string(obj): CRS object has comment, which is lost in output
## Variable(s) "Ii" contains positive and negative values, so midpoint is set to 0. Set midpoint = NA to show the full spectrum of the color palette.
## Warning in sp::proj4string(obj): CRS object has comment, which is lost in output

## Warning in sp::proj4string(obj): CRS object has comment, which is lost in output
## Variable(s) "Ii" contains positive and negative values, so midpoint is set to 0. Set midpoint = NA to show the full spectrum of the color palette.
## Warning in sp::proj4string(obj): CRS object has comment, which is lost in output

Below are the LocalMI plot and Pvalue plot for e-week 32

tmap_arrange(localMIPlot_week32, pvaluePlot_week32, asp=1, ncol=2)
## Warning in sp::proj4string(obj): CRS object has comment, which is lost in output
## Variable(s) "Ii" contains positive and negative values, so midpoint is set to 0. Set midpoint = NA to show the full spectrum of the color palette.
## Warning in sp::proj4string(obj): CRS object has comment, which is lost in output

Part 4: Local Getis-Ord Gi* analysis

4.1 Derive spatial weight matrix

For this part of the study, instead of using a fixed distance to derive the proximity matrix, we will use the adaptive distance method, which is a fixed number of neighbours.

# Convert sf object of central mexico to spatial object 
central_mexico <- as_Spatial(central_mexico_sf)
## Warning in showSRID(uprojargs, format = "PROJ", multiline = "NO", prefer_proj =
## prefer_proj): Discarded datum Unknown based on GRS80 ellipsoid in CRS definition
## Warning in showSRID(SRS_string, format = "PROJ", multiline = "NO", prefer_proj =
## prefer_proj): Discarded datum International Terrestrial Reference Frame 2008 in
## CRS definition
# Prepare knb
coords <- coordinates(central_mexico)
knb <- knn2nb(knearneigh(coords, k=8, longlat = TRUE), row.names=row.names(central_mexico@data$NOMGEO))
## Warning in knearneigh(coords, k = 8, longlat = TRUE): knearneigh: coordinates
## are not geographical: longlat argument wrong
knb_lw <- nb2listw(knb, style = 'B')
summary(knb_lw)
## Characteristics of weights list object:
## Neighbour list object:
## Number of regions: 176 
## Number of nonzero links: 1408 
## Percentage nonzero weights: 4.545455 
## Average number of links: 8 
## Non-symmetric neighbours list
## Link number distribution:
## 
##   8 
## 176 
## 176 least connected regions:
## 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 with 8 links
## 176 most connected regions:
## 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 with 8 links
## 
## Weights style: B 
## Weights constants summary:
##     n    nn   S0   S1    S2
## B 176 30976 1408 2502 45988

4.2 Prepare GI Plot from e-week 13 to e-week 32 using adaptive distance method.

for(i in 13:32){
  weekly_rate<-paste0("covidrate_wk",i)
  week_num <- paste0("week", i)
  GIObj <- paste0("GI",i)
  adaptive_df <- data.frame("gstat_adaptive" = as.matrix(localG(central_mexico[[weekly_rate]], knb_lw)))
  GIObj <- cbind(central_mexico, adaptive_df)
  GI.Plot_name <- paste0("GIPlot_week", i)
  # for each e-week, output different GI plot respectively  
  GI.Plot <- tm_shape(GIObj) +
    tm_fill(col = "gstat_adaptive",
          style = "pretty",
          palette = "-RdBu",
          title = "Local Gi Plot") +
    tm_borders(alpha=1) +
    tm_layout(week_num,
              title.size = 0.5,
              panel.label.size = 0.5,
              legend.title.size = 0.5,
              legend.text.size = 0.5)
  assign(GI.Plot_name, GI.Plot)
}

From e-week13 to e-week 18

tmap_arrange(GIPlot_week13,GIPlot_week14,GIPlot_week15,GIPlot_week16,GIPlot_week17,GIPlot_week18)
## Warning in sp::proj4string(obj): CRS object has comment, which is lost in output
## Variable(s) "gstat_adaptive" contains positive and negative values, so midpoint is set to 0. Set midpoint = NA to show the full spectrum of the color palette.
## Warning in sp::proj4string(obj): CRS object has comment, which is lost in output
## Variable(s) "gstat_adaptive" contains positive and negative values, so midpoint is set to 0. Set midpoint = NA to show the full spectrum of the color palette.
## Warning in sp::proj4string(obj): CRS object has comment, which is lost in output
## Variable(s) "gstat_adaptive" contains positive and negative values, so midpoint is set to 0. Set midpoint = NA to show the full spectrum of the color palette.
## Warning in sp::proj4string(obj): CRS object has comment, which is lost in output
## Variable(s) "gstat_adaptive" contains positive and negative values, so midpoint is set to 0. Set midpoint = NA to show the full spectrum of the color palette.
## Warning in sp::proj4string(obj): CRS object has comment, which is lost in output
## Variable(s) "gstat_adaptive" contains positive and negative values, so midpoint is set to 0. Set midpoint = NA to show the full spectrum of the color palette.
## Warning in sp::proj4string(obj): CRS object has comment, which is lost in output
## Variable(s) "gstat_adaptive" contains positive and negative values, so midpoint is set to 0. Set midpoint = NA to show the full spectrum of the color palette.
## Warning in sp::proj4string(obj): CRS object has comment, which is lost in output
## Variable(s) "gstat_adaptive" contains positive and negative values, so midpoint is set to 0. Set midpoint = NA to show the full spectrum of the color palette.
## Warning in sp::proj4string(obj): CRS object has comment, which is lost in output
## Variable(s) "gstat_adaptive" contains positive and negative values, so midpoint is set to 0. Set midpoint = NA to show the full spectrum of the color palette.
## Warning in sp::proj4string(obj): CRS object has comment, which is lost in output
## Variable(s) "gstat_adaptive" contains positive and negative values, so midpoint is set to 0. Set midpoint = NA to show the full spectrum of the color palette.
## Warning in sp::proj4string(obj): CRS object has comment, which is lost in output
## Variable(s) "gstat_adaptive" contains positive and negative values, so midpoint is set to 0. Set midpoint = NA to show the full spectrum of the color palette.
## Warning in sp::proj4string(obj): CRS object has comment, which is lost in output
## Variable(s) "gstat_adaptive" contains positive and negative values, so midpoint is set to 0. Set midpoint = NA to show the full spectrum of the color palette.
## Warning in sp::proj4string(obj): CRS object has comment, which is lost in output
## Variable(s) "gstat_adaptive" contains positive and negative values, so midpoint is set to 0. Set midpoint = NA to show the full spectrum of the color palette.

From e-week19 to e-week 24

tmap_arrange(GIPlot_week19,GIPlot_week20,GIPlot_week21,GIPlot_week22,GIPlot_week23,GIPlot_week24)
## Warning in sp::proj4string(obj): CRS object has comment, which is lost in output
## Variable(s) "gstat_adaptive" contains positive and negative values, so midpoint is set to 0. Set midpoint = NA to show the full spectrum of the color palette.
## Warning in sp::proj4string(obj): CRS object has comment, which is lost in output
## Variable(s) "gstat_adaptive" contains positive and negative values, so midpoint is set to 0. Set midpoint = NA to show the full spectrum of the color palette.
## Warning in sp::proj4string(obj): CRS object has comment, which is lost in output
## Variable(s) "gstat_adaptive" contains positive and negative values, so midpoint is set to 0. Set midpoint = NA to show the full spectrum of the color palette.
## Warning in sp::proj4string(obj): CRS object has comment, which is lost in output
## Variable(s) "gstat_adaptive" contains positive and negative values, so midpoint is set to 0. Set midpoint = NA to show the full spectrum of the color palette.
## Warning in sp::proj4string(obj): CRS object has comment, which is lost in output
## Variable(s) "gstat_adaptive" contains positive and negative values, so midpoint is set to 0. Set midpoint = NA to show the full spectrum of the color palette.
## Warning in sp::proj4string(obj): CRS object has comment, which is lost in output
## Variable(s) "gstat_adaptive" contains positive and negative values, so midpoint is set to 0. Set midpoint = NA to show the full spectrum of the color palette.
## Warning in sp::proj4string(obj): CRS object has comment, which is lost in output
## Variable(s) "gstat_adaptive" contains positive and negative values, so midpoint is set to 0. Set midpoint = NA to show the full spectrum of the color palette.
## Warning in sp::proj4string(obj): CRS object has comment, which is lost in output
## Variable(s) "gstat_adaptive" contains positive and negative values, so midpoint is set to 0. Set midpoint = NA to show the full spectrum of the color palette.
## Warning in sp::proj4string(obj): CRS object has comment, which is lost in output
## Variable(s) "gstat_adaptive" contains positive and negative values, so midpoint is set to 0. Set midpoint = NA to show the full spectrum of the color palette.
## Warning in sp::proj4string(obj): CRS object has comment, which is lost in output
## Variable(s) "gstat_adaptive" contains positive and negative values, so midpoint is set to 0. Set midpoint = NA to show the full spectrum of the color palette.
## Warning in sp::proj4string(obj): CRS object has comment, which is lost in output
## Variable(s) "gstat_adaptive" contains positive and negative values, so midpoint is set to 0. Set midpoint = NA to show the full spectrum of the color palette.
## Warning in sp::proj4string(obj): CRS object has comment, which is lost in output
## Variable(s) "gstat_adaptive" contains positive and negative values, so midpoint is set to 0. Set midpoint = NA to show the full spectrum of the color palette.

From e-week25 to e-week 30

tmap_arrange(GIPlot_week25,GIPlot_week26,GIPlot_week27,GIPlot_week28,GIPlot_week29,GIPlot_week30)
## Warning in sp::proj4string(obj): CRS object has comment, which is lost in output
## Variable(s) "gstat_adaptive" contains positive and negative values, so midpoint is set to 0. Set midpoint = NA to show the full spectrum of the color palette.
## Warning in sp::proj4string(obj): CRS object has comment, which is lost in output
## Variable(s) "gstat_adaptive" contains positive and negative values, so midpoint is set to 0. Set midpoint = NA to show the full spectrum of the color palette.
## Warning in sp::proj4string(obj): CRS object has comment, which is lost in output
## Variable(s) "gstat_adaptive" contains positive and negative values, so midpoint is set to 0. Set midpoint = NA to show the full spectrum of the color palette.
## Warning in sp::proj4string(obj): CRS object has comment, which is lost in output
## Variable(s) "gstat_adaptive" contains positive and negative values, so midpoint is set to 0. Set midpoint = NA to show the full spectrum of the color palette.
## Warning in sp::proj4string(obj): CRS object has comment, which is lost in output
## Variable(s) "gstat_adaptive" contains positive and negative values, so midpoint is set to 0. Set midpoint = NA to show the full spectrum of the color palette.
## Warning in sp::proj4string(obj): CRS object has comment, which is lost in output
## Variable(s) "gstat_adaptive" contains positive and negative values, so midpoint is set to 0. Set midpoint = NA to show the full spectrum of the color palette.
## Warning in sp::proj4string(obj): CRS object has comment, which is lost in output
## Variable(s) "gstat_adaptive" contains positive and negative values, so midpoint is set to 0. Set midpoint = NA to show the full spectrum of the color palette.
## Warning in sp::proj4string(obj): CRS object has comment, which is lost in output
## Variable(s) "gstat_adaptive" contains positive and negative values, so midpoint is set to 0. Set midpoint = NA to show the full spectrum of the color palette.
## Warning in sp::proj4string(obj): CRS object has comment, which is lost in output
## Variable(s) "gstat_adaptive" contains positive and negative values, so midpoint is set to 0. Set midpoint = NA to show the full spectrum of the color palette.
## Warning in sp::proj4string(obj): CRS object has comment, which is lost in output
## Variable(s) "gstat_adaptive" contains positive and negative values, so midpoint is set to 0. Set midpoint = NA to show the full spectrum of the color palette.
## Warning in sp::proj4string(obj): CRS object has comment, which is lost in output
## Variable(s) "gstat_adaptive" contains positive and negative values, so midpoint is set to 0. Set midpoint = NA to show the full spectrum of the color palette.
## Warning in sp::proj4string(obj): CRS object has comment, which is lost in output
## Variable(s) "gstat_adaptive" contains positive and negative values, so midpoint is set to 0. Set midpoint = NA to show the full spectrum of the color palette.

From e-week31 to e-week 32

tmap_arrange(GIPlot_week31,GIPlot_week32)
## Warning in sp::proj4string(obj): CRS object has comment, which is lost in output
## Variable(s) "gstat_adaptive" contains positive and negative values, so midpoint is set to 0. Set midpoint = NA to show the full spectrum of the color palette.
## Warning in sp::proj4string(obj): CRS object has comment, which is lost in output
## Variable(s) "gstat_adaptive" contains positive and negative values, so midpoint is set to 0. Set midpoint = NA to show the full spectrum of the color palette.
## Warning in sp::proj4string(obj): CRS object has comment, which is lost in output
## Variable(s) "gstat_adaptive" contains positive and negative values, so midpoint is set to 0. Set midpoint = NA to show the full spectrum of the color palette.
## Warning in sp::proj4string(obj): CRS object has comment, which is lost in output
## Variable(s) "gstat_adaptive" contains positive and negative values, so midpoint is set to 0. Set midpoint = NA to show the full spectrum of the color palette.

4.3 Analysis of the Plots above

Based on the preset legend, red spots represent the “hot” spots whereas blue spots represent the “cold” spots. As one can observe from the GI plots across the weeks, there are some distinctive pattern that can be noticed.

Based on the visualisations, there are generally less hot and less cold spots during the first few time periods. Althought there is a small number of hot and cold spots, their colours are of lighter shade, meaning that the relative COVID-19 rates during this first time period is low.

However, as time passes and reaches the mid-point of the study time period, both hot and cold spots are of darker shades and are more spread out, illustrating how the COVID-19 cases spread in central mexico and grew rapidly in number.

Towards the end of the study time period, the hot and cold spots become generally lighter in shade, which could be due to the fact that the COVID-19 cases are more evenly spread out across Central Mexico and no particular city has distinctively higher/lower COVID-19 cases, as opposed to during the first few e-weeks.