-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathmalaria.Rmd
More file actions
223 lines (161 loc) · 8 KB
/
malaria.Rmd
File metadata and controls
223 lines (161 loc) · 8 KB
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
---
title: "Malaria"
output:
html_document:
toc: true
toc_float: true
number_sections: false
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE, message = FALSE, warning = FALSE)
library(tidyverse)
library(DT)
library(ggthemes)
```
#### Data set details
|||
| ----------- | ----------- |
| **Data set description:** | Malaria data in different locations |
| **Source:** | [Malaria Atlas Project](https://malariaatlas.org/) |
| **Details on the retrieved data:** | Parasite rate (PR) survey data and vector occurrence data in Zimbabwe and India. |
| **Spatial and temporal resolution:** | Malaria data at country level (with information on specific sites). |
# Downloading and visualising malaria data with `malariaAtlas`
This tutorial shows how to use the `malariaAtlas` package to download, visualize and manipulate global malaria data hosted by the [Malaria Atlas Project](https://malariaatlas.org/). These data can be explored and downloaded interactively at [data explorer](https://malariaatlas.org/explorer/#/).
The `malariaAtlas` package enables users to download three types of data:
- parasite rate (PR) survey data (*Plasmodium falciparum* and *Plasmodium vivax*)
- vector occurrence data
- administrative boundary shapefiles to visualise data
- rasters covering a range of modelled outputs related to malaria research such as predicted malaria parasite prevalence
## Installation of `malariaAtlas` package
The `malariaAtlas` package can be installed from CRAN and loaded as follows:
```{r install-malariaAtlas, eval=FALSE}
install.packages("malariaAtlas")
```
```{r load-lib}
library(malariaAtlas)
```
## Checking available data
The `malariaAtlas` package provides users with a convenient API to interact with the publicly available malaria data hosted by the Malaria Atlas Project.
The `listData()` function helps retrieve a list of all the available data which can be downloaded, and is a wrapper for `listPoints()`, `listRaster()` and `listShp()`.
We can find all countries that have PR survey points data with `listData(datatype = "pr points")`,
and all countries with vector occurrence data with `listData(datatype = "vector points")`.
We can also see raster data available with `listData(datatype = "raster")`,
and shapefiles available with `listData(datatype = "shape")`.
The `isAvailable_pr()` function can be used to check whether a specified country or location has PR survey points.
Similarly, `isAvailable_vec()` checks whether a specified country or location has vector occurrence data.
For example, we can check whether Zimbabwe has PR survey points and India has vector occurrence data as follows:
```{r func_pr, message = FALSE}
isAvailable_pr(country = "Zimbabwe")
isAvailable_vec(country = "India")
```
## Dowloading and visualising data
### PR survey data
The `getPR()` function downloads all the publicly available PR points for a country (or countries) and returns it as a dataframe. The `species` argument is a string specifying the Plasmodium species and can be `Pf`, `Pv` or `BOTH`.
```{r get-pr,message = FALSE,warning=FALSE}
ZM_PR_data <- getPR(country = "Zimbabwe", species = "BOTH")
```
```{r, echo=FALSE}
ZM_PR_data %>%
datatable(extensions = c("Scroller", "FixedColumns"), options = list(
deferRender = TRUE,
scrollY = 350,
scrollX = 350,
dom = "t",
scroller = TRUE,
fixedColumns = list(leftColumns = 4)
))
```
`autoplot()` can be used to quickly and easily visualise the downloaded PR survey points.
```{r viz-PR, message=FALSE,warning=FALSE}
autoplot(ZM_PR_data)
```
### Vector data
The `getVecOcc()` function downloads all publicly available vector points for a country (or countries) and returns it as a dataframe. The `species` argument is a string specifying the Anopheles species for finding the vector occurrences points, the options are `Anopheles....` or `ALL`.
```{r get-vec,message = FALSE,warning=FALSE}
IN_VEC_data <- getVecOcc(country = "India", species = "ALL")
```
```{r, echo=FALSE}
IN_VEC_data %>%
datatable(extensions = c("Scroller", "FixedColumns"), options = list(
deferRender = TRUE,
scrollY = 350,
scrollX = 350,
dom = "t",
scroller = TRUE,
fixedColumns = list(leftColumns = 4)
))
```
`autoplot()` uses `ggplot2` to visualise vector occurrence data.
```{r message = FALSE}
autoplot(IN_VEC_data)
```
### Shapefiles
The `getShp()` function downloads a shapefile for a specified country (or countries).
The `as.MAPshp()` function converts the SpatialPolygon downloaded using `getShp()` into a `MAPshp` object (data.frame) for easy plotting with `autoplot()`.
```{r message = FALSE}
IN_shp <- getShp(ISO = "IND", admin_level = c("admin1"))
IN_shp <- as.MAPshp(IN_shp)
autoplot(IN_shp)
```
### Modelled Rasters
The `getRaster()` function downloads publicly available rasters for a specific surface and year, clipped to a given bounding box or shapefile. For example we can download Plasmodium falciparum PR2-10 for Zimbabwe in 2010 as follows:
```{r message = FALSE}
ZM_shp <- getShp(country = "Zimbabwe", admin_level = "admin0")
ZMB_Pf <- getRaster(surface = "Plasmodium falciparum PR2-10", shp = ZM_shp, year = 2010)
```
Note that to use downloaded rasters and shapefiles directly with `autoplot()`, they must first be converted to usable rasters and shapefiles data frames, hence we use the `as.MAPraster()` and `as.MAPShp()` respectively.
```{r message = FALSE}
ZMB_Pf <- as.MAPraster(ZMB_Pf)
ZMB_shp_data <- as.MAPshp(ZM_shp)
autoplot(ZMB_Pf, shp_df = ZMB_shp_data)
```
## Complete visualisation examples
Since the `ggplot2` is loaded as dependency when the `malariaAtlas` package is loaded, the functionalities of `ggplot2` can also be used for more appeal and options.
### PR survey points
```{r message = FALSE}
ZMB_shp <- getShp(country = "Zimbabwe", admin_level = "admin0") # get shapefile
ZMB_shp_df <- as.MAPshp(ZMB_shp) # convert shapefile
ZMB_PfPR2_10 <- getRaster(surface = "Plasmodium falciparum PR2-10", shp = ZMB_shp, year = 2013) # get raster
ZMB_PfPR2_10_df <- as.MAPraster(ZMB_PfPR2_10) # convert raster
pr <- getPR(country = c("Zimbabwe"), species = "Pf") # get PR data
p <- autoplot(ZMB_PfPR2_10_df, shp_df = ZMB_shp_df, printed = FALSE) # plot raster and shapefile
p[[1]] + geom_point(
data = pr[pr$year_start == 2013, ],
aes(longitude, latitude, fill = positive / examined, size = examined), shape = 21
) +
scale_size_continuous(name = "Survey Size") +
scale_fill_distiller(name = "PfPR", palette = "RdYlBu") +
ggtitle("Raw PfPR Survey points\n + Plasmodium falciparum PR2-10 in Zimbabwe in 2013") +
theme_solarized() +
labs(x = "Longitude", y = "Latitude")
```
### Vector points
```{r message = FALSE}
IND_shp <- getShp(country = "India", admin_level = "admin0") # get shapefile
IND_shp_df <- as.MAPshp(IND_shp) # convert shapefile
IND_an_dirus <- getRaster(surface = "Anopheles dirus species complex", shp = IND_shp) # get raster
IND_an_dirus_df <- as.MAPraster(IND_an_dirus) # convert raster
vec <- getVecOcc(country = c("India"), species = "Anopheles dirus") # get vector point data
p <- autoplot(IND_an_dirus_df, shp_df = IND_shp_df, printed = FALSE) # plot raster and shapefile
p[[1]] + geom_point(data = vec, aes(longitude, latitude), shape = 21, show.legend = TRUE) +
scale_fill_distiller(name = "Predicted distribution", palette = "YlOrRd") +
ggtitle("Raw Vector Survey points + \nThe predicted distribution of Anohpeles dirus species complex") +
theme(legend.position = "bottom") +
theme_solarized() +
labs(x = "Longitude", y = "Latitude")
```
## References
- The `malariaAtlas` package repository : https://github.com/malaria-atlas-project/malariaAtlas
- Malaria Atlas Project: https://malariaatlas.org/
- Malaria data explorer: https://malariaatlas.org/explorer/#/
---
<p style ="color:grey; font-size: 13px;">
Last updated: `r Sys.Date()`
Source code: https://github.com/rspatialdata/rspatialdata.github.io/blob/main/malaria.Rmd
<details>
<summary><span style ="color:grey; font-size: 13px;">Tutorial was complied using: (click to expand)</span></summary>
```{r echo=FALSE}
sessionInfo()
```
</details>
</p>