Examples
Sebastian Camilo Loos
examples.Rmd
The following article is an example that shows how to work with the data package and produce insights using R.
Setting things up
Read in Data Sets
First, additional files including data sets with specific census data about Blantyre has been added to the package from https://data.humdata.org. For this fictional article we will use spatial data and therefore, the data has to be read in as simple features using the sf-package
as you can see in the following code junk.
# read in ward boundaries data
census_boundaries <-
st_read(here::here("vignettes", "articles",
"traditional-authorities", "Malawi_TA_2018.shp")) |>
st_as_sf()
# read in traditional authority population data
census_data <- read_csv(here::here("vignettes", "articles",
"traditional-authorities",
"census_data.csv"))
# read waste skips locations into a simple feature (spatial vector data)
# set coordinate reference system equal to one from census_boundaries
sf_wsb <- st_as_sf(wasteskipsblantyre, coords = c('long', 'lat')) |>
st_set_crs(value = 4326) |>
st_transform(st_crs(census_boundaries))
Background
Malawi is an eastern sub-Saharan state. For this article the area of the city of Blantyre has been explored as depicted in the following map section.
![Boundaries of the Wards in Blantyre.](images/map-boundaries-blantyre.png)
The city is divided in 23 traditional authorities. This article will use these areas to explore and emphasize on the data contained in the wasteskipsblantyre
package. The data set stores the locations of publicly accessible waste skips in Blantyre (map below) and was collected in 2021.
census_boundaries |>
filter(DIST_NAME == "Blantyre City") |>
group_by(TA_NAME) |>
summarise(TA_CODE, OBJECTID) |>
qtm() +
qtm(sf_wsb)
![Locations of the publically accessable waste skips in Blantyre, Malawi.](images/map-locations.png)
In addition, data from the 2018 Malawi Census population data set shared by National Statistical Office is used for some demographic analysis.
Hypothesis
In the context of this fictional article we define a hypothesis:
The number of waste skips within traditional authorities (wards) correlates with the area of each authority.
Analysis
First, we have a separate look into the the the waste skips data and the data from the 2018 census for each ward within Blantyre which are also called wards. After that we compare the the two data sets and look for possible correlations.
Waste Skips Data
The location of 53 public waste skips has been determined. In Figure 1 it is visible that number of waste skips in a ward vary between 0 and 4. On average, there are 2.2 waste skips in a ward.
![Number of waste skips in each ward.](examples_files/figure-html/figure-count-ta-1.png)
Figure 1: Number of waste skips in each ward.
The city center is located to the west of the city. In the map below, a slight difference between the western and the north-eastern wards can be recognized. Nevertheless, it is very difficult to see any tendencies with regard to geographical location of the waste skips. At most, one could say that there tend to be more waste skips in the western part of Blantyre, where the city center is located.
# join data sets
join_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)
join_dataset |>
group_by(TA_NAME) |>
summarise(n = factor(sum(capacity_l)/7000)) |>
mutate(n = factor(n, levels = c(0:4))) |>
tm_shape() +
tm_borders() +
tm_fill(col = "n", palette = "RdPu", alpha = 0.7) +
qtm(sf_wsb)
![Wards coulered according to the number of waste skips that they have within their boundaries.](images/map-count.png)
Population Data Figure
#> [1] "800,264"
In 2018, Blantyre City’s population was 800,264. The population for each ward can be seen the following Figure 2.
![Population per ward.](examples_files/figure-html/figure-barplot-pop-1.png)
Figure 2: Population per ward.
Since the areas of the wards differ, we will have a look into the population density of the wards in Figure 3.
![Population density per ward.](examples_files/figure-html/figure-barplot-density-1.png)
Figure 3: Population density per ward.
Comparison
In order to cross check the data and validate the hypothesis the data sets are linked together and visualized in the following figures.
Figure 4 doesn’t really show a correlation between the number of waste skips and the population of the wards. Nevertheless, the four most populated wards have more than 3 waste skips.
![Ward population, coloured by the number of waste skips within the ward.](examples_files/figure-html/figure-count-pop-1.png)
Figure 4: Ward population, coloured by the number of waste skips within the ward.
Also the population density appears to not have an influence on the placement of a waste skip as seen in Figure 5. It is interesting to see that the Ndirande Makata Ward and the Ndirande Gamulani Ward do not have a waste skip even though they are the 3rd and 4th most densely populated areas of the city.
![Ward population density, coloured by the number of waste skips within the ward.](examples_files/figure-html/figure-count-density-1.png)
Figure 5: Ward population density, coloured by the number of waste skips within the ward.
Conclusion
The hypothesis could not be verified. There is no clear correlation between the location of waste skips and the population of the wards of Blantyre.
We hope you enjoyed this fictional article!
Please, check the source code for more insights.