-
Notifications
You must be signed in to change notification settings - Fork 2
/
_14-case-study2.Rmd
213 lines (186 loc) · 7.3 KB
/
_14-case-study2.Rmd
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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
# Case study 2 Mapping real-time COVID cases in Malawi {#case-study2}
## Overall goal of the chapter
Building on the spatial data skills from previous chapters, this chapter will show how to map the spread of COVID-19 across Malawi using the interactive visualization tools Leaflet and Plotly in R Studio. The goal of this case study is to demonstrate how skills from this book can be applied to the analysis and visualization of real-world challenges to help raise awareness, curb misinformation and inform public health decision making.
This case study seeks to demonstrate how spatial epidemiologists and the wider mapping community can use interactive mapping tools to improve understanding and communication of diseases using spatial disease patterns. This step by step description is a template for the visualization for a plethora of diseases.
<br/>
In 2019 the World Health Organization confirmed the worldwide coronavirus pandemic (COVID-19) caused by the severe acute respiratory syndrome coronavirus 2 (SARS-CoV-2). For the first time, in April 2020, the virus was reported in the two largest cities of Malawi. Within a few months it spread from the cities of Blantyre and Lilongwe to all districts of Malawi- affecting the lives of thousands of people. Here we visualize the spread across Malawi using the steps described below.
**I don't think we need learning outcomes, as this is a case study.**
<br/>
## Section 1: Data importation {#episode_1_importation}
First, let's make sure all the necessary data management packages are loaded
```{r, warning=FALSE, message=FALSE}
# library(dplyr) #load dplyr package
# library(readxl) # package for loading Excel files
# library(sf)
# library(mapview)
# library(rgdal)
# library(leaflet)
# library(leaflet.extras)
# library(plotly) #plotting interactive graphs
# library(htmltools)
# library(RColorBrewer)
```
Now, open the necessary data files
```{r, warning=FALSE, message=FALSE}
# # identify working directory
# getwd()
#
# # Read in district boundary shapefile for Malawi
# malawi_districts <- readOGR("data/mw_districts.shp")
#
# # Read in district level COVID-19 data
# covid <- read_xlsx("data/Malawi_subnational_covid_cases_Jan_2020.xlsx")
```
Check that the data files are loaded properly
```{r}
# covid
#
# malawi_districts@data
#
# plot(malawi_districts) # too basic
#
# mapView(malawi_districts, color = "transparent", label = "DISTRICT") # more polished
```
## Section 2: Data cleaning {#episode_2_cleaning}
```{r}
# # calculate active cases
# covid <- covid |>
# mutate(Active = Confirmed - (Deaths + Recovered))
# covid
#
# # Merge COVID-19 data with boundary data using unique identifier FID (district ID)
# covid_by_district <- merge(malawi_districts, covid, by.x = "fid", by.y = "Fid")
#
# # Check if merging has worked
# covid_by_district@data
```
## Section 3: Visualisation {#episode_3_visualisation}
```{r}
#
# # Create COVID-19 intercative graphs
# bar_chart <- covid |>
# filter(District != "Zomba City",
# District != "Lilongwe",
# District != "Blantyre")|> # remove redundant data
# plot_ly(y = ~District,
# x = ~Confirmed,
# type = "bar",
# orientation = "h",
# name = "Confirmed",
# marker = list(color = "purple")
# ) %>%
# plotly::add_trace(
# x = ~Deaths,
# name = "Death",
# marker = list(color = "red")
# ) %>%
# plotly::add_trace(
# x = ~Recovered,
# name = "Recovered",
# marker = list(color = "green")
# ) %>%
# plotly::add_trace(
# x = ~Active,
# name = "Active",
# marker = list(color = "orange")
# ) %>%
# plotly::layout(
# barmode = "stack",
# xaxis = list(title = "Total cases"),
# yaxis = list(title = ""),
# hovermode = "compare",
# margin = list(
# b = 10,
# t = 10,
# pad = 2
# )
# )
# bar_chart
# # Create COVID-19 interactive maps
#
# bins <- c(0, 10, 50, 100, 500, 1000, 2500, 5000, 11000) # create bins based on the maximum number of COVID-19 cases
#
# pal <- colorBin("YlOrRd", domain = covid_by_district, bins = bins) # Yellow, orange and red color palette for cases
#
# labels <- paste("<h3 style='color:red'>Covid-19 cases</h3>",
# "<b>", covid$District, "<br>",
# "<b>Confirmed:</b>", covid$Confirmed, "<br>",
# "<b>Deaths:</b>", covid$Deaths, "<br>",
# "<b>Recovered:</b>", covid$Recovered, "<br>",
# "<b>Active cases:</b>", covid$Active, "<br>",
# sep = " ") # Create labels using HTML
#
#
# covid_map <- leaflet() |>
# setView(lng = 33.7, lat = -13.9, zoom = 6) |> # zoom to area of interest using coordinates for Malawi
# addProviderTiles(providers$CartoDB) |> # add basemap
# addPolygons(data = covid_by_district,
# group = "Active",
# weight = 1,
# smoothFactor = 1,
# color = "gray",
# fillOpacity = 1,
# fillColor = ~ pal(Active),
# label = lapply(labels, HTML)) |>
# addPolygons(data = covid_by_district,
# group = "Confirmed",
# weight = 1,
# smoothFactor = 1,
# color = "gray",
# fillOpacity = 1,
# fillColor = ~ pal(Confirmed),
# label = lapply(labels, HTML)) |>
# addPolygons(data = covid_by_district,
# group = "Deaths",
# weight = 1,
# smoothFactor = 1,
# color = "gray",
# fillOpacity = 1,
# fillColor = ~ pal(Deaths),
# label = lapply(labels, HTML)) |>
# addPolygons(data = covid_by_district,
# group = "Recovered",
# weight = 1,
# smoothFactor = 1,
# color = "gray",
# fillOpacity = 1,
# fillColor = ~ pal(Recovered),
# label = lapply(labels, HTML))
#
# covid_map
#
# # Let's add map items
# # a) Layers control
# covid_map |>
# addLayersControl(
# baseGroups = c("Confirmed", "Active", "Deaths", "Recovered"),
# options = layersControlOptions(collapsed = FALSE)) |>
# # b) Legend
# addLegend(pal = pal,
# values = c(1:11000),
# opacity = 0.7,
# title = "Covid-19 Cases",
# position = "bottomright") |>
# # c) scale bar
# addScaleBar(position = "bottomleft")
# # d) add map title
# # First, let's create a title using HTML and CSS style
# # Map title using CSS styles and HTML
# title <- tags$style(HTML(".map-title{
# transform:translate(-10%,20%);position:fixed!important;
# left:10%;text-align:left;padding-left:10px;
# padding-right:10px;background:rgba(255,255,255,0.75);
# font-weight:bold;font-size:15px}"))
#
# map_title <- tags$div(title, HTML("COVID-19 cases as of 05 January 2020"))
#
# covid_map |>
# addControl(map_title, position = "topleft", className = "map-title")
#
# covid_map
```
## Section 4: {#episode_4_}
## Further resources
In this section we provide links to additional websites and sources that are useful in a given topic or package in the following way:
## Summary
This closing section should show the reader what has been done in this chapter and how it links with the topics provided in the next chapter by a brief introduction to next topic.