-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsaint-louis-healthsites-osm-survey.Rmd
427 lines (311 loc) · 13.4 KB
/
saint-louis-healthsites-osm-survey.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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
---
title: "OSM survey of Saint Louis Health Facilities 2022"
#output: html_document
author: "Andy South @afrimapr"
date: "`r Sys.Date()`"
output: pdf_document
urlcolor: blue
always_allow_html: true
---
DRAFT
[Code for this document](https://github.com/afrimapr/senegal-healthsites-2022/blob/master/saint-louis-healthsites-osm-survey.Rmd)
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE, warning = FALSE, message=FALSE)
library(knitr)
library(tidyverse)
library(sf)
library(tmap)
```
```{r read-data-osm, include=FALSE}
# get local file data, can't share yet
folder <- "C:\\Users\\andy.south\\Google Drive\\afrimapr-gdrive\\Proposals\\2022-01-senegal-covidaction\\data\\"
filename_lamine <- "2022-02-28-lamine-kobo.csv"
filename_lamine <- paste0(folder,filename_lamine)
#dfosm <- read_csv(filename_lamine)
#394 rows 289 columns
#sorts accents
dfosm <- read_csv(filename_lamine, locale=locale(encoding = "ISO-8859-1"))
#convert column names to lowercase & remove any accents and spaces
names(dfosm) <- names(dfosm) %>%
#fix accents
str_conv(encoding = "ISO-8859-1") %>%
#remove accents
stringi::stri_trans_general("Latin-ASCII") %>%
#lower case
str_to_lower() %>%
#replace spaces with _
str_replace_all("\\s", "_") %>%
#remove _facility_location_ before coords
str_replace_all("_facility_location_", "") %>%
str_replace_all("\\?", "") %>%
str_replace_all("what_is_the_number_of_", "") %>%
str_replace_all("speciality_medical_equipment_available/","") %>%
str_replace_all("available_services/","") %>%
str_replace_all("does_this_facility_provide_","")
#dfosm$in_which_health_zone_is_the_facility_located
#[1] NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA
# dfosm2 <- dfosm %>% select(name_of_facility,
# city,
# operator_type,
# longitude,
# latitude,
# operational_status,
# facility_category,
# number_of_beds,
# number_of_doctors,
# number_of_nurses)
# which column from original osm data contains the data ?
# [8] "name_of_facility"
# [16] "operator_type"
# [19] "latitude"
# [20] "longitude"
# [48] "facility_category"
# [54] "functional_medicalized_ambulances"
# [55] "functional_non-medical_ambulances"
# [63] "functional_ambulance_launches"
# [124] "state_midwives"
# [210] "available_services"
# [222] "birthing_center"
# [234] "emergency_department"
# [235] "does_this_facility_provide_emergency_services"
# [237] "number_of_beds"
# [238] "number_of_doctors"
# [239] "number_of_nurses"
dfosm2 <- dfosm[,c(8,16,19,20,48,54,55,63,124,210,222,234,235,237,238,239)]
table(dfosm2$facility_category)
# Clinic Dentist Doctors Hospital Pharmacy
# 15 2 294 22 61
```
```{r make-geo-osm, include=FALSE}
sfosm <- st_as_sf(dfosm2,
coords=c("longitude", "latitude"),
crs=4326)
```
### Categories of health facilities Saint Louis from OSM survey
```{r map-osm-sl, eval=TRUE, fig.height=4}
#, fig.show='hold'
library(tmap)
library(afriadmin)
sfsen_adm0 <- afriadmin('senegal',level=0, plot=FALSE)
sfsen_adm1 <- afriadmin('senegal',level=1, plot=FALSE)
#map category types
tmap::tm_shape(filter(sfsen_adm1, shapeName=="Saint Louis")) +
tm_borders("grey", lwd = .5) +
tm_shape(sfsen_adm0) +
tm_borders("black", lwd = .5) +
tm_shape(sfosm) +
#tm_dots(shape=3, size = 0.15, col='red', border.lwd = 0.2) +
# Clinic Dentist Doctors Hospital Pharmacy
# 15 2 294 22 61
#0square,1circle,2triangle,3+,4x
tm_symbols(shape="facility_category", col='red', shapes=c(0,1,3,2,4), size=0.1) +
tm_layout(main.title='OSM health facilities Saint Louis 2022', main.title.size=1,
legend.bg.color=TRUE, legend.position=c("center","BOTTOM"),
title="map by @afrimapr", title.color="darkgrey", title.size=0.8, title.position=c("RIGHT","BOTTOM")) #main.title goes above map
#map operator_type
tmap::tm_shape(filter(sfsen_adm1, shapeName=="Saint Louis")) +
tm_borders("grey", lwd = .5) +
tm_shape(sfsen_adm0) +
tm_borders("black", lwd = .5) +
tm_shape(sfosm) +
# table(dfosm$operator_type)
#Community Government Private Public Religious
# 29 2 74 261 1
#0square,1circle,2triangle,3+,4x
tm_symbols(shape="operator_type", col='red', shapes=c(0,1,2,3,4), size=0.1) +
tm_layout(main.title='OSM health facilities Saint Louis 2022', main.title.size=1,
legend.bg.color=TRUE, legend.position=c("center","BOTTOM"),
title="map by @afrimapr", title.color="darkgrey", title.size=0.8, title.position=c("RIGHT","BOTTOM")) #main.title goes above map
#add NA points, have to do separately because shapeNA doesn't work for size
# tm_shape(sfsen_sur[is.na(sfsen_sur$beds),]) +
# tm_dots(shape=3, size = 0.15, col='grey', border.lwd = 0.2) +
# tm_shape(sfsen_sur) +
# tm_symbols(col = "building", alpha=0.8, size = "beds", size.max=420,
# scale=3, sizes.legend=c(10,100,400), title.col="") +
# tm_add_legend(type="symbol", shape=3, labels = "no bed data", size = 0.5, border.lwd = 0.5, col = "grey") +
# tm_scale_bar(breaks=c(0,50,100), position=c("LEFT", "BOTTOM")) +
```
## Numbers from OSM data
```{r map-osm-attributes, eval=TRUE, fig.height=4, fig.show='hold'}
columns <- c("number_of_beds","number_of_doctors","number_of_nurses")
for(column_to_map in columns)
{
#cat(column_to_map)
# can I do in ggplot to allow repel of labels ?
library(ggplot2)
library(ggrepel)
gg <- ggplot(filter(sfsen_adm1, shapeName=="Saint Louis")) +
geom_sf() +
theme_void() +
geom_sf(data=sfosm, size=0.3) +
geom_text_repel(data=sfosm, aes(label=.data[[column_to_map]], geometry=geometry),
stat="sf_coordinates",
#padding default is 0.25
box.padding = 0.1,
#force=0.5,
segment.size = 0.1, segment.alpha = 0.7,
#point.padding = NA, #allows points to overlap centroid
colour='red', size=1.9
) +
labs(title = paste("OSM", column_to_map))
# gg <- ggplot(africountries) +
# geom_sf(aes(fill = pop_est)) +
# scale_fill_viridis_c() +
# theme_void() +
# geom_text_repel(aes(label=name_long, geometry=geometry),
# stat="sf_coordinates",
# point.padding = NA, #allows points to overlap centroid
# colour='darkgrey', size=3
# ) +
# labs(title = "Population by country 2000", fill = "Population Estimate")
plot(gg)
}
```
## Compare OSM survey data to PATH data
```{r read-data-path, include=FALSE}
# get local file data, can't share yet
# saved first sheet from xls as csv
# xls emailed from Mark
folder <- "C:\\Users\\andy.south\\Google Drive\\afrimapr-gdrive\\Proposals\\2022-01-senegal-covidaction\\data\\"
filename <- "2022-02-senegal-structures.csv"
filename <- paste0(folder,filename)
#read in csv
#encoding fixes accents
dfpath <- read_csv(filename, locale=locale(encoding = "ISO-8859-1"))
# [1] "Région Médicale" "District de Santé" "Structure sanitaire" "Type structure"
# [5] "Autre type structure" "Statut" "Latitude" "Longitude"
#convert column names to lowercase & remove any accents and spaces
names(dfpath) <- names(dfpath) %>%
#fix accents
#str_conv(encoding = "ISO-8859-1") %>%
#remove accents
stringi::stri_trans_general("Latin-ASCII") %>%
#lower case
str_to_lower() %>%
#replace spaces with _
str_replace_all("\\s", "_")
table(dfpath$type_structure)
# autre CMG CS HP PS RM
# 36 1 100 12 1322 14
# This legend appears in one file
# Type structure
# PS Poste de Santé
# DS District de Sanitaire (Centre de santé)
# CS Centre de Santé
# HP Hopital
# RM Région Médical
# autre (Clinique, maternité, unité de vaccination, Dispensaire, etc;)
table(dfpath$statut) #priv-publ
# Communautaire Prive conf Prive laic Public
# 1 39 35 1410
```
```{r make-geo-path, include=FALSE}
sfpath <- st_as_sf(dfpath,
coords=c("longitude", "latitude"),
na.fail = FALSE, crs=4326)
sfpath_sl <- filter(sfpath, region_medicale == "Saint Louis")
table(sfpath_sl$type_structure)
# autre CMG CS HP PS RM
# 2 1 6 1 110 1
```
```{r map-path-osm-sl, eval=TRUE, fig.height=4}
#, fig.show='hold'
library(tmap)
library(afriadmin)
sfsen_adm0 <- afriadmin('senegal',level=0, plot=FALSE)
sfsen_adm1 <- afriadmin('senegal',level=1, plot=FALSE)
sfsen_adm1_sl <- filter(sfsen_adm1, shapeName=="Saint Louis")
#map statut (publ/priv)
tmap::tm_shape(sfsen_adm1_sl) +
tm_borders("grey", lwd = .5) +
tm_shape(sfsen_adm0) +
tm_borders("black", lwd = .5) +
tm_shape(sfpath_sl) +
#0square,1circle,2triangle,3+,4x
tm_symbols(shape="statut", col='darkgreen', shapes=c(0,1,2,3), size=0.3) +
tm_shape(sfosm) +
# table(dfosm$operator_type)
#Community Government Private Public Religious
# 29 2 74 261 1
#shape 0square,1circle,2triangle,3+,4x
tm_symbols(shape="operator_type", col='red', shapes=c(0,1,2,3,4), size=0.05) +
tm_layout(main.title='OSM(red) & PATH(green) health facilities Saint Louis 2022', main.title.size=1,
legend.bg.color=TRUE, legend.position=c("center","BOTTOM"),
title="map by @afrimapr", title.color="darkgrey", title.size=0.8, title.position=c("RIGHT","BOTTOM")) #main.title goes above map
```
```{r map-path-osm-sl-dept, eval=FALSE, fig.height=4}
sfsen_adm2 <- afriadmin('senegal',level=2, plot=FALSE)
#subset adm2 for Saint Louis
#sfsen_adm2_sl <- sfsen_adm2[sfsen_adm1_sl,]
#sfsen_adm2_sl <- st_intersection(sfsen_adm2, sfsen_adm1_sl)
#unfortunately this includes more than 3 expected depts
#mapview(sfsen_adm2_sl, zcol="shapeName")
#simpler way
sfsen_adm2_sl <- filter(sfsen_adm2, shapeName %in% c("Saint Louis","Dagana","Podor"))
# TODO
# better to use 5 health districts - I have the data from PATH
```
```{r map-emergency-osm, eval=TRUE, fig.height=4}
# request from Mark
# Can you create a map thsat shows the Emergency health services?
# As a pregnant women I want to have access to an ambulance or convenient transportation should I need to access emergency health services during labor.
# which column from original osm data contains the data ?
# [8] "name_of_facility"
# [16] "operator_type"
# [19] "latitude"
# [20] "longitude"
# [54] "functional_medicalized_ambulances"
# [55] "functional_non-medical_ambulances"
# [63] "functional_ambulance_launches"
# [124] "state_midwives"
# [210] "available_services"
# [222] "birthing_center"
# [234] "emergency_department"
# [235] "emergency_services"
# [237] "number_of_beds"
# [238] "number_of_doctors"
# [239] "number_of_nurses"
#dfosm_emergency <- dfosm[,c(8,16,19,20,54,55,63,124,210,222,234,235,237,238,239)]
#table(dfosm$emergency_services)
# No NON OUI Yes
# 265 7 17 46
#sfosm_emergency <- filter(sfosm, emergency_services=="Yes")
sfosm_emergency <- filter(sfosm, emergency_services%in%c("Yes","OUI"))
sfosm_emergency$emergency_services <- "Yes"
sfosm_birthing <- filter(sfosm, birthing_center==1)
gg <- ggplot(filter(sfsen_adm1, shapeName=="Saint Louis")) +
geom_sf() +
theme_void() +
geom_sf(data=sfosm, size=0.3) +
#geom_sf(data=sfosm_emergency, colour='red', size=5, shape="+", show.legend="point") +
geom_sf(data=sfosm_emergency, aes(colour=emergency_services), size=5, shape="+", show.legend="point") +
theme(legend.position = "bottom") +
labs(title = paste("Facilities providing Emergency services, OSM-Senegal survey"))
gg
#birthing centers
#shape 0square,1circle,2triangle,3+,4x
gg <- ggplot(filter(sfsen_adm1, shapeName=="Saint Louis")) +
geom_sf() +
theme_void() +
geom_sf(data=sfosm, size=0.3) +
geom_sf(data=sfosm_birthing, colour="blue", size=3, shape=1) +
# geom_sf(data=sfosm_birthing, aes(colour=birthing_center), size=3, shape=1, show.legend="point") +
# theme(legend.position = "bottom") +
labs(title = paste("Facilities with Birthing centres, OSM-Senegal survey"))
gg
```
```{r mapview-path-osm, eval=FALSE, fig.height=4}
# to compare PATH & osm-survey data in interactive map
# will only work in html not pdf.
# or could put into a shiny app
#todo get label working
mapvosm <- mapview::mapview(sfosm,
zcol="facility_category",
label=paste("osm:",sfosm[["name_of_facility"]]),
col.regions = RColorBrewer::brewer.pal(9, "YlGn"))
mapvpath <- mapview::mapview(sfpath_sl,
zcol="type_structure",
label=paste("osm:",sfpath_sl$structure_sanitaire),
col.regions = RColorBrewer::brewer.pal(9, "BuPu"))
mapvosm + mapvpath
```