-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfor_students.R
223 lines (103 loc) · 5.09 KB
/
for_students.R
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
library(tidyverse)
library(tmap)
tmap_mode('view')
tmap_options(check.and.fix = TRUE)
# Defining the study area -------------------------------------------------
library(sf)
lga <- st_read('data/GRID3_Nigeria_-_Local_Government_Area_Boundaries/GRID3_Nigeria_-_Local_Government_Area_Boundaries.shp')
lga %>%
st_drop_geometry() %>%
View()
tm_shape(lga)+
tm_polygons()
lga_Ado <- lga %>%
filter(lga_name_x=='Ado Odo/Ota')
# EXERCISE: can you build an interactive map of the LGAs in Nigeria using Leaflet?
# Discovering the health facilities dataset -------------------------------
health_facilities <- st_read('data/GRID3_Nigeria_-_Health_Care_Facilities_/GRID3_Nigeria_-_Health_Care_Facilities_.shp')
# exploration
health_facilities %>%
st_drop_geometry() %>%
View()
health_facilities_Ado <- health_facilities %>%
filter(lga_name=='Ado Odo/Ota')
# EXERCISE: How many health facilities in Ado Odo/Ota?
tm_shape(health_facilities_Ado)+
tm_dots(col='type', size=0.07, id='primary_na', popup.vars=c('category','functional','source'))+
tm_basemap('OpenStreetMap')+
tm_shape(lga_Ado)+
tm_borders(lwd=4)
# EXERCISE: How many health facilities are offering tertiary services in Ado Odo/Ota?
# Discovering the gridded population dataset ------------------------------
library(raster)
pop <- raster('data/NGA_population_v2_0_gridded/NGA_population_v2_0_gridded.tif')
pop_Ado <- crop(pop, lga_Ado)
plot(pop_Ado)
pop_Ado <- mask(pop_Ado, lga_Ado)
plot(pop_Ado)
tm_shape(health_facilities_Ado)+
tm_dots(col='type', size=0.07, id='primary_na', popup.vars=c('category','functional','source'))+
tm_basemap('OpenStreetMap')+
tm_shape(pop_Ado)+
tm_raster()+
tm_shape(lga_Ado)+
tm_borders(lwd=4)
# Buffering points --------------------------------------------------------
library(units)
health_facilities_Ado_buffered <- st_buffer(health_facilities_Ado, dist=set_units(1, km))
health_facilities_Ado[1,]
tm_shape(pop_Ado)+
tm_raster()+
tm_shape(health_facilities_Ado_buffered[1,])+
tm_borders()+
tm_shape(health_facilities_Ado[1,])+
tm_dots( size=0.08, id='primary_na', popup.vars=c('category','functional','source'))+
tm_basemap('OpenStreetMap')
# Computing the population ------------------------------------------------
health_facilities_Ado_pop <- raster::extract(pop_Ado, health_facilities_Ado_buffered, fun=sum, na.rm=T,df=T)
health_facilities_Ado_buffered$pop <- health_facilities_Ado_pop$NGA_population_v2_0_gridded
#EXERCISE: How many people are living in 1km of Ado Odo Ii Health Center?
summary(health_facilities_Ado_buffered$pop)
hist(health_facilities_Ado_buffered$pop, breaks=20)
tm_shape(health_facilities_Ado_buffered)+
tm_fill('pop', style='pretty', id='pop')+
tm_shape(health_facilities_Ado)+
tm_dots( size=0.08, id='primary_na', popup.vars=c('category','functional','source'))+
tm_basemap('OpenStreetMap')
tm_shape(health_facilities_Ado_buffered %>%
filter(pop<1000))+
tm_fill( id='pop', alpha=0.5, col='grey20')+
tm_shape(pop_Ado)+
tm_raster()+
tm_basemap('OpenStreetMap')
# How many people are not covered by health facilities? ------------------
health_facilities_Ado_buffered_rasterized <- rasterize(health_facilities_Ado_buffered, pop_Ado, field=1)
plot(health_facilities_Ado_buffered_rasterized)
pop_Ado_masked <- mask(pop_Ado, health_facilities_Ado_buffered_rasterized)
plot(pop_Ado_masked)
sum(pop_Ado_masked[], na.rm=T)
#EXERCISE: How many people are not living in a 1km of an health facility?
# How many are not covered by a maternity home? ---------------------------
tm_shape(pop_Ado)+
tm_raster()+
tm_shape(health_facilities_Ado)+
tm_dots( size=0.08, id='primary_na', popup.vars=c('category','functional','source'))+
tm_shape(health_facilities_Ado %>%
filter(category=='Maternity Home'))+
tm_dots(col='darkgreen', size=0.08, id='primary_na', popup.vars=c('category','functional','source'))+
tm_basemap('OpenStreetMap')
# EXERCISE: How many maternity homes are listed in the LGA?
# EXERCISE: How many people are not living in a 1km distance of a maternity center?
# What is the furthest a woman has to travel to reach a maternity? --------
health_facilities_Ado_maternity <- health_facilities_Ado %>%
filter(category=='Maternity Home')
health_facilities_Ado_maternity_distance <- distanceFromPoints(pop_Ado, health_facilities_Ado_maternity)
plot(health_facilities_Ado_maternity_distance)
health_facilities_Ado_maternity_distance_pop <- mask(health_facilities_Ado_maternity_distance, pop_Ado)
plot(health_facilities_Ado_maternity_distance_pop)
summary(health_facilities_Ado_maternity_distance_pop[])
#EXERCISE: How many people are living at more than 8km from a maternity?
# And how many woman of childbearing age?... -----------------------------------------------------
women <- raster('data/NGA_population_v2_0_agesex/NGA_population_v2_0_agesex_f15_49.tif')
#EXERCISE: How many women of childbearing age are living at more than 8km from a maternity?
# EXERCISE: What about the number of women of childbearing age living at more than 8km from a maternity in the country?