-
Notifications
You must be signed in to change notification settings - Fork 0
/
README.Rmd
328 lines (272 loc) · 11.9 KB
/
README.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
---
output: github_document
editor_options:
chunk_output_type: console
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%",
message = FALSE,
warning = FALSE,
fig.retina = 2,
fig.align = 'center'
)
library(tidyverse)
library(epoxy)
library(universityrankingafrica)
```
# basisghana
<!-- badges: start -->
[![R-CMD-check](https://github.com/openwashdata/basisghana/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/openwashdata/basisghana/actions/workflows/R-CMD-check.yaml)
[![DOI](https://zenodo.org/badge/676448371.svg)](https://zenodo.org/doi/10.5281/zenodo.10255444)
<!-- badges: end -->
This package compiles sanitation data from established Open Defecation Free (ODF) communities across different regions in Ghana.
```{r, echo=FALSE}
library(sf)
library(rnaturalearth)
library(ggplot2)
library(tidyverse)
library(basisghana)
library(dplyr)
basisghananew <- basisghana |>
rename(district_en = "district") |>
mutate(district_en = case_when(
district_en == "Abura Asebu Kwamankes" ~ "Abura-Asebu-Kwamankese",
district_en == "Ajumako Enyan Essiam" ~ "Ajumako-Enyan-Essiam",
district_en == "Asikuma Odoben Brakwa" ~ "Asikuma-Odoben-Brakwa",
district_en == "Bawku" ~ "Bawku Municipal",
district_en == "Bunkpurugu" ~ "Bunkpurugu Nakpanduri",
district_en == "Daffiama Bussie Iss" ~ "Daffiama Bussie Issa",
district_en == "East Gonja" ~ "East Gonja Municipal",
district_en == "Garu Tempane" ~ "Garu",
district_en == "Ho" ~ "Ho Municipal",
district_en == "Hohoe" ~ "Hohoe Municipal",
district_en == "Keta" ~ "Keta Municipal",
district_en == "Kpando Municipa" ~ "Kpando Municipal",
district_en == "Lambussie Karni" ~ "Lambussie-Karni",
district_en == "Nadowli Kaleo" ~ "Nadowli-Kaleo",
district_en == "Sagnarigu" ~ "Sagnerigu",
district_en == "Tatale" ~ "Tatale Sanguli",
district_en == "West Mamprusi" ~ "West Mamprusi Municipal",
district_en == "Yendi" ~ "Yendi Municipal",
district_en == "Damongo" ~ "West Gonja",
TRUE ~ district_en
))
odf_by_district <- basisghananew |>
group_by(district_en) |>
summarize(odf_population = sum(population, na.rm = TRUE))
odf_by_district <- merge(odf_by_district, ghanapop, by = 'district_en', all = TRUE) |>
mutate(percentage = round(odf_population / total_pop * 100, 2)) |>
arrange(desc(percentage))
top_10_odf <- odf_by_district |>
top_n(10, percentage) |>
select(district_en, region_en, percentage) |>
mutate(percentage = paste0(percentage, "%")) |>
rename(
district = "district_en",
region = "region_en",
`proportion ODF population in district` = "percentage"
)
#group the regions according to how they were back in 2017 (10 regions instead of 16)
odf_by_region <- odf_by_district |>
mutate(region_en = case_when(
region_en %in% c("Bono", "Bono East", "Ahafo") ~ "Brong Ahafo",
region_en %in% c("Northern", "Savannah", "Northern East") ~ "Northern",
region_en %in% c("Volta", "Oti") ~ "Volta",
region_en %in% c("Western", "Western North") ~ "Western",
TRUE ~ as.character(region_en)
)) |>
group_by(region_en) |>
summarize(
odf_population = sum(odf_population, na.rm = TRUE),
female = sum(female_pop, na.rm = TRUE),
male = sum(male_pop, na.rm = TRUE),
total_pop = sum(total_pop, na.rm = TRUE)
) |>
mutate(percentage = round(odf_population / total_pop * 100, 2)) |>
arrange(desc(percentage)) |>
filter(!is.na(region_en)) |>
select(region_en, percentage)
ghana <- ne_states(country = "Ghana", returnclass = "sf") |>
rename(
region_en = "name"
)
ggplot() +
theme_void() +
geom_sf(data = full_join(ghana, odf_by_region, by = "region_en"), aes(fill = percentage), color = "white", lwd = 0) +
scale_fill_gradientn(name = paste("Percentage of ODF population", "\n by region (logarithmic scale)"),
trans = "log",
labels = scales::label_number(accuracy = 1),
colors = c("#2E8B57","#9DBF9E", "#FCB97D", "#A84268"),
na.value = "grey80") +
labs(title = paste("Regions with highest percentage of ODF communities", "\n in Ghana (2017)")) +
theme_minimal() +
theme(
plot.title = element_text(size = 14),
plot.margin = margin(1, 1, 1, 1, "cm")
)
```
## Installation
You can install the development version of basisghana from [GitHub](https://github.com/) with:
``` r
# install.packages("devtools")
devtools::install_github("openwashdata/basisghana")
```
Alternatively, you can download the individual dataset as a CSV or XLSX
file from the table below.
```{r, echo=FALSE}
extdata_path <- "https://github.com/openwashdata/basisghana/raw/main/inst/extdata/"
read_csv("data-raw/dictionary.csv") |>
distinct(file_name) |>
mutate(file_name = str_remove(file_name, ".rda")) |>
rename(dataset = file_name) |>
mutate(
CSV = paste0("[Download CSV](", extdata_path, dataset, ".csv)"),
XLSX = paste0("[Download XLSX](", extdata_path, dataset, ".xlsx)")
) |>
knitr::kable()
```
## Project goal
The primary goal of BaSIS (Basic Sanitation Information System) within the context of implementing Community-Led Total Sanitation (CLTS) in Ghana is to combat open defecation. By collecting data on communities practicing open defecation, the project aims to shift away from previous subsidy-based approaches and focus on community engagement. BaSIS seeks to empower communities, particularly in regions like Upper West, Eastern, Northern, Volta, and Central, to abandon open defecation practices through CLTS. The objective is to break the cycle of fecal-oral contamination, reduce the spread of diseases linked to poor sanitation, and promote sustainable, community-driven solutions to improve overall hygiene and sanitation practices.
## Data
The data set includes the locations of the existing open defecation free (ODF) communities in
various districts of Ghana. It was last updated in September 2017.
The package provides access to two data sets.
```{r, echo = TRUE}
library(basisghana)
```
The `basisghana` data set has `r ncol(basisghana)`
variables and `r nrow(basisghana)` observations. For an overview
of the variable names, see the following table.
```{r, eval=FALSE}
basisghana
```
```{r, echo=FALSE}
readr::read_csv("data-raw/dictionary.csv") |>
dplyr::filter(file_name == "basisghana.rda") |>
dplyr::select(variable_name:description) |>
knitr::kable()
```
The `ghanapop` data set has `r ncol(ghanapop)`
variables and `r nrow(ghanapop)` observations. For an overview
of the variable names, see the following table.
```{r, eval=FALSE}
ghanapop
```
```{r, echo=FALSE}
readr::read_csv("data-raw/dictionary.csv") |>
dplyr::filter(file_name == "ghanapop.rda") |>
dplyr::select(variable_name:description) |>
knitr::kable()
```
## Example
```{r, echo=FALSE}
library(basisghana)
library(dplyr)
library(tidyverse)
basisghana <- basisghana |>
rename(district_en = "district") |>
mutate(district_en = case_when(
district_en == "Abura Asebu Kwamankes" ~ "Abura-Asebu-Kwamankese",
district_en == "Ajumako Enyan Essiam" ~ "Ajumako-Enyan-Essiam",
district_en == "Asikuma Odoben Brakwa" ~ "Asikuma-Odoben-Brakwa",
district_en == "Bawku" ~ "Bawku Municipal",
district_en == "Bunkpurugu" ~ "Bunkpurugu Nakpanduri",
district_en == "Daffiama Bussie Iss" ~ "Daffiama Bussie Issa",
district_en == "East Gonja" ~ "East Gonja Municipal",
district_en == "Garu Tempane" ~ "Garu",
district_en == "Ho" ~ "Ho Municipal",
district_en == "Hohoe" ~ "Hohoe Municipal",
district_en == "Keta" ~ "Keta Municipal",
district_en == "Kpando Municipa" ~ "Kpando Municipal",
district_en == "Lambussie Karni" ~ "Lambussie-Karni",
district_en == "Nadowli Kaleo" ~ "Nadowli-Kaleo",
district_en == "Sagnarigu" ~ "Sagnerigu",
district_en == "Tatale" ~ "Tatale Sanguli",
district_en == "West Mamprusi" ~ "West Mamprusi Municipal",
district_en == "Yendi" ~ "Yendi Municipal",
district_en == "Damongo" ~ "West Gonja",
TRUE ~ district_en
))
```
### 1) Extracting the Top 10 Districts with the Highest Percentage of ODF Communities in Ghana
The following code demonstrates how to calculate the percentage of ODF communities per region in Ghana. This computation involves using ODF population data sourced from the basisghana dataset, in conjunction with total population statistics categorized by region, sourced from the ghanapop dataset.
```{r example}
library(tidyverse)
library(basisghana)
library(dplyr)
odf_by_district <- basisghana |>
group_by(district_en) |>
summarize(odf_population = sum(population, na.rm = TRUE))
odf_by_district <- merge(odf_by_district, ghanapop, by = 'district_en', all = TRUE) |>
mutate(percentage = round(odf_population / total_pop * 100, 2)) |>
arrange(desc(percentage))
top_10_odf <- odf_by_district |>
top_n(10, percentage) |>
select(district_en, region_en, percentage) |>
mutate(percentage = paste0(percentage, "%")) |>
rename(
district = "district_en",
region = "region_en",
`proportion ODF population in district` = "percentage"
)
top_10_odf
```
### 2) Mapping the Regions with highest percentage of ODF communities in Ghana
The code uses the dataset of ODF communities categorized by districts (see above), which are then aggregated based on regions in Ghana. It's important to note that the reference to Ghana's regions pertains to the former 10 regions preceding the 2018 referendum, which subsequently led to the establishment of new regions, resulting in a total of 16 regions from 2020 (Refer to [Regions of Ghana](https://en.wikipedia.org/wiki/Regions_of_Ghana)). From the collected data across 5 of these former regions, a color-coded map of Ghana depicts the varying proportions of Open Defecation Free (ODF) communities in each region.
```{r}
library(sf)
library(rnaturalearth)
library(ggplot2)
#group the regions according to how they were back in 2017 (10 regions instead of 16)
odf_by_region <- odf_by_district |>
mutate(region_en = case_when(
region_en %in% c("Bono", "Bono East", "Ahafo") ~ "Brong Ahafo",
region_en %in% c("Northern", "Savannah", "Northern East") ~ "Northern",
region_en %in% c("Volta", "Oti") ~ "Volta",
region_en %in% c("Western", "Western North") ~ "Western",
TRUE ~ as.character(region_en)
)) |>
group_by(region_en) |>
summarize(
odf_population = sum(odf_population, na.rm = TRUE),
female = sum(female_pop, na.rm = TRUE),
male = sum(male_pop, na.rm = TRUE),
total_pop = sum(total_pop, na.rm = TRUE)
) |>
mutate(percentage = round(odf_population / total_pop * 100, 2)) |>
arrange(desc(percentage)) |>
filter(!is.na(region_en)) |>
select(region_en, percentage)
ghana <- ne_states(country = "Ghana", returnclass = "sf") |>
rename(
region_en = "name"
)
ggplot() +
theme_void() +
geom_sf(data = full_join(ghana, odf_by_region, by = "region_en"), aes(fill = percentage), color = "white", lwd = 0) +
scale_fill_gradientn(name = paste("Percentage of ODF population", "\n by region (logarithmic scale)"),
trans = "log",
labels = scales::label_number(accuracy = 1),
colors = c("#2E8B57","#9DBF9E", "#FCB97D", "#A84268"),
na.value = "grey80") +
labs(title = paste("Regions with highest percentage of ODF communities", "\n in Ghana (2017)")) +
theme_minimal() +
theme(
plot.title = element_text(size = 14),
plot.margin = margin(1, 1, 1, 1, "cm")
)
```
*Note: A logarithmic scale has been employed to accentuate distinctions among lower percentage values.*
## License
Data are available as
[CC-BY](https://github.com/openwashdata/basisghana/LICENSE.md).
## Citation
To cite this package, please use:
```{r}
citation("basisghana")
```