-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREADME.Rmd
166 lines (123 loc) · 5.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
---
output: github_document
always_allow_html: true
editor_options:
markdown:
wrap: 72
chunk_output_type: console
bibliography: references.bib
---
<!-- 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%"
)
library(tidyverse)
```
# wsabrazil
<!-- badges: start -->
[![License: CC BY 4.0](https://img.shields.io/badge/License-CC_BY_4.0-darkorange.svg)](https://creativecommons.org/licenses/by/4.0/)
[![R-CMD-check](https://github.com/openwashdata/wsabrazil/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/openwashdata/wsabrazil/actions/workflows/R-CMD-check.yaml)
<!-- badges: end -->
This package contains information related to wastewater management practices and household infrastructure in Brazil. It includes variables such as sector codes, metropolitan region names, municipality codes, and names, as well as data on the location type, living conditions, average income, and household amenities. The data provides insights into wastewater disposal habits, water supply sources, bathroom facilities, and sanitation infrastructure in Brazilian households, contributing to understanding environmental sustainability and infrastructure development efforts. @atlas
![](man/figures/Rplot04.png)
Based on the data, it appears for example that most of the municipalities exhibits poor housing conditions. In this dataset, housing conditions are represented numerically, with '1' indicating correct housing conditions and '0' indicating poor housing conditions. The location map displays all Brazilian municipalities from which data has been collected.
## Installation
You can install the development version of wsabrazil from [GitHub](https://github.com/) with:
```r
# install.packages("devtools")
devtools::install_github("openwashdata/wsabrazil")
```
Alternatively, you can download the dataset as a CSV or XLSX
file from the table below.
```{r, echo=FALSE, message=FALSE, warning=FALSE}
extdata_path <- "https://github.com/openwashdata/wsabrazil/raw/main/inst/extdata/"
read_csv("data-raw/dictionary.csv") |>
distinct(file_name) |>
dplyr::mutate(file_name = str_remove(file_name, ".rda")) |>
dplyr::rename(dataset = file_name) |>
mutate(
CSV = paste0("[Download CSV](", extdata_path, dataset, ".csv)"),
XLSX = paste0("[Download XLSX](", extdata_path, dataset, ".xlsx)")
) |>
knitr::kable()
```
## Data
The dataset includes observations of wastewater management practices and household infrastructure (access to water and sanitation services) across various regions in Brazil.
The package provides access to one single dataset.
```{r, echo = TRUE}
library(wsabrazil)
```
The `wsabrazil` dataset has `r ncol(wsabrazil)`
variables and `r nrow(wsabrazil)` observations. For an overview
of the variable names, see the following table.
```{r, eval=FALSE}
wsabrazil
```
```{r, echo=FALSE, message=FALSE, warning=FALSE}
readr::read_csv("data-raw/dictionary.csv") |>
dplyr::filter(file_name == "wsabrazil.rda") |>
dplyr::select(variable_name:description) |>
knitr::kable() |>
kableExtra::kable_styling() |>
kableExtra::scroll_box(height = "400px")
```
## Examples
### 1. Housing conditions across municipalities
The location map displayed above was created as follows:
```{r eval=FALSE, message=FALSE, warning=FALSE, include=TRUE, paged.print=FALSE}
library(wsabrazil)
library(ggplot2)
library(sf)
library(dplyr)
shapefile <- st_read("man/gadm41_BRA_2.json")
merged_data <- merge(shapefile, wsabrazil, by.x = "CC_2", by.y = "municipality_code")
# Plot the choropleth map
ggplot() +
geom_sf(data = merged_data, aes(fill = as.factor(sector_type))) +
scale_fill_manual(name = "sector_type", values = c("0" = "#E69F00", "1" = "#0072B2"),
labels = c("0" = "poor", "1" = "correct")) +
labs(title = "Housing conditions across municipalities") +
theme(plot.title = element_text(hjust = 0.5, face = "bold", color = "#333333", size = 24),
legend.title = element_text(face = "bold", color = "#333333", size = 16),
legend.text = element_text(color = "#333333", size = 16))
```
### 2. Water supply in Brazil
From the dataset, we can also explore the distribution of water sources in the whole country. We create here a horizontal bar plot to visualize the frequency of different water sources available, utilizing variables such as piped water or stored rainwater. We observe from the resulting plot (see Figure below) that the majority of private households are supplied by piped water. Interestingly, almost none of the households store rainwater. This is possibly due to factors such as local climate patterns and infrastructure limitations.
```{r, eval=FALSE}
library(dplyr)
library(ggplot2)
library(wsabrazil)
library(tidyr)
data_long_summary <- wsabrazil |>
pivot_longer(cols = piped_water:other_water_source,
names_to = "water_source",
values_to = "frequency") |>
group_by(water_source) |>
summarise(total_frequency = sum(frequency, na.rm = TRUE)) |>
arrange(total_frequency)
# Create a horizontal bar plot of water source types
plot <- ggplot(data_long_summary, aes(x = total_frequency, y = reorder(water_source, total_frequency))) +
geom_col(fill = "#0072B2") +
labs(x = "Frequency", y = "Water Source",
title = "Water supply in Brazil",
caption = "") +
theme(plot.title = element_text(hjust = 0.5, face = "bold", color = "#333333"))
plot + scale_x_continuous(labels = scales::number_format())
```
![](man/figures/Rplot01.png)
## License
Data are available as
[CC-BY](https://github.com/openwashdata/wsabrazil/LICENSE.md).
## Citation
To cite this package, please use:
```{r}
citation("wsabrazil")
```
## References
```{html, echo = FALSE}
<div id="refs"></div>
```