forked from openwashdata/wasteskipsblantyre
-
Notifications
You must be signed in to change notification settings - Fork 0
/
README.Rmd
231 lines (182 loc) · 6.8 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
---
output: github_document
editor_options:
chunk_output_type: console
markdown:
wrap: 72
execute:
echo: false
---
<!-- 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(sf)
library(tidyverse)
library(tmap)
library(wasteskipsblantyre)
```
# wasteskipsblantyre
<!-- badges: start -->
[![DOI](https://zenodo.org/badge/483225869.svg)](https://zenodo.org/badge/latestdoi/483225869)
[![R-CMD-check](https://github.com/openwashdata/wasteskipsblantyre/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/openwashdata/wasteskipsblantyre/actions/workflows/R-CMD-check.yaml)
<!-- badges: end -->
The goal of wasteskipsblantyre is to provide a dataset for
research and planning of solid waste management in Blantyre, Malawi. The
dataset includes locations of the publicly accessible waste skips in in
the city. The data was collected in 2021 and has not been updated since.
```{r, echo=FALSE, message=FALSE, warning=FALSE, dpi=300}
census_boundaries <-
st_read(here::here("vignettes", "articles",
"traditional-authorities", "Malawi_TA_2018.shp"),
quiet = TRUE) |>
st_as_sf()
census_data <- read_csv(here::here("vignettes", "articles",
"traditional-authorities",
"census_data.csv"))
sf_wsb <- st_as_sf(wasteskipsblantyre, coords = c('long', 'lat')) |>
st_set_crs(value = 4326) |>
st_transform(st_crs(census_boundaries))
joined_dataset <- st_join(census_boundaries, sf_wsb) |>
mutate(name = ifelse((DIST_NAME == "Blantyre City")*is.na(name),
yes = TA_NAME, no = name)) |>
mutate(capacity_l = ifelse((DIST_NAME == "Blantyre City")*(is.na(capacity_l)),
yes = 0, no =capacity_l)) |>
drop_na(capacity_l)
pop_ta <- joined_dataset |>
group_by(TA_NAME) |>
summarise(n = sum(capacity_l)/7000) |>
left_join(census_data) |>
summarise(ta_pop = sum(TOTAL_POP), .by = TA_NAME)
count_ta <- joined_dataset |>
group_by(TA_NAME) |>
summarise(n = sum(capacity_l)/7000) |>
mutate(mean_number = mean(n))
#st_drop_geometry(count_ta) |>
# left_join(st_drop_geometry(pop_ta)) |>
# ggplot(aes(x = ta_pop, y = forcats::fct_rev(TA_NAME))) +
# geom_col(aes(fill = factor(n))) +
# scale_fill_brewer(palette = "RdPu") +
# labs(title = "Ward population and number of waste skips",
# subtitle = "Greater population does not indicate greater number of #skips",
# x = "Ward Population",
# y = "Ward in Blantyre",
# fill = "Number of publicly\naccessible waste skips") +
# theme_bw()
```
```{r, echo=FALSE, message=FALSE, warning=FALSE}
st_drop_geometry(count_ta) |>
left_join(st_drop_geometry(pop_ta)) |>
mutate(n = factor(n)) |>
ggplot(aes(x = n, y = ta_pop, color = n)) +
geom_boxplot(outlier.shape = NA, lwd = 0.8) +
geom_jitter(width = 0.15, size = 4, alpha = 0.4, color = "black") +
labs(title = "Number of waste skips and population",
subtitle = "Greater population does not indicate greater number of skips",
y = "Population",
x = "Waste skips (n)",
color = "Number of publicly\naccessible waste skips") +
scale_color_brewer(palette = "RdPu") +
scale_y_continuous(breaks = seq(0, 100000, 10000),
limits = c(0, 100000),
expand = c(0, 0, 0.05, 0),
labels = scales::label_number(
scale_cut = scales::cut_short_scale()
)) +
theme_gray() +
theme(panel.grid.minor = element_blank(),
panel.grid.major.x = element_blank(),
axis.line = element_line(),
panel.background = element_rect(fill = "white"),
panel.grid.major = element_line("grey95", linewidth = 0.25),
legend.key = element_rect(fill = NA))
```
## Installation
You can install the development version of wasteskipsblantyre from
[GitHub](https://github.com/) with:
```{r eval=FALSE, echo=TRUE}
# install.packages("devtools")
devtools::install_github("openwashdata/wasteskipsblantyre")
```
Alternatively, you can download the individual datasets as a CSV or XLSX
file from the table below.
```{r, echo=FALSE}
extdata_path <- "https://github.com/openwashdata/wasteskipsblantyre/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
Data on the location of public waste skips in Blanytre was not
available. Without such data, it becomes difficult to develop a solid
waste management plan and logistics. The goal of this project was to
identify the locations of public waste skips in Blantyre, Malawi.
## Data
The data set includes the locations of the publicly accessible waste
skips in Blantyre, Malawi. The data was collected in 2021.
```{r, echo = TRUE}
library(wasteskipsblantyre)
```
The `wasteskipsblantyre` data set has `r ncol(wasteskipsblantyre)`
variables and `r nrow(wasteskipsblantyre)` observations. For an overview
of the variable names, see the following table.
```{r, eval=FALSE}
wasteskipsblantyre
```
```{r, echo=FALSE}
readr::read_csv("data-raw/dictionary.csv") |>
dplyr::select(variable_name:description) |>
knitr::kable()
```
```{r, echo=FALSE}
#| label: fig-waste-skips-simple
#| fig-cap: Locations of waste skips in this dataset
sf_wsb <- st_as_sf(wasteskipsblantyre, coords = c('long', 'lat'), crs = 4326)
tmap_mode("plot")
sf_wsb |>
tm_shape() +
tm_dots() +
tm_graticules()
```
## Example
The code below is an example which shows how you could use the data to
prepare a map in R. Find this and more examples in the [prepared
examples
article](https://openwashdata.github.io/wasteskipsblantyre/articles/examples.html)
(`vignette("examples")`).
```{r example, eval=FALSE, echo=TRUE}
library(wasteskipsblantyre)
library(sf)
library(tmap)
# read data set into a simple feature (spatial vector data)
sf_wsb <- st_as_sf(wasteskipsblantyre, coords = c('long', 'lat'), crs = 4326)
# set mapping mode to interactive ("view")
tmap_mode("view")
# create an interactive map
qtm(sf_wsb)
```
```{r, echo=FALSE, fig.cap="Screenshot of the an interactive map with OpenStreetMap layer."}
knitr::include_graphics("man/figures/screenshot-map-waste-skips-blantyre.png")
```
## License
Data are available as
[CC-BY](https://github.com/openwashdata/wasteskipsblantyre/blob/main/LICENSE.md).
## Citation
Please cite using:
```{r}
citation("wasteskipsblantyre")
```