-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathREADME.Rmd
291 lines (193 loc) · 10.1 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
---
output:
md_document:
preserve_yaml: false
---
```{r, echo = FALSE, message = FALSE, results = "hide", warning = FALSE}
library(malariaAtlas)
library(tibble)
knitr::opts_chunk$set(fig.path = 'man/figures/')
```
# malariaAtlas
### An R interface to open-access malaria data, hosted by the Malaria Atlas Project.
*The gitlab version of the malariaAtlas package has some additional bugfixes over the stable CRAN package. If you have any issues, try installing the latest github version. See below for instructions.*
# Overview
This package allows you to download parasite rate data (*Plasmodium falciparum* and *P. vivax*), survey occurrence data of the 41 dominant malaria vector species, and modelled raster outputs from the [Malaria Atlas Project](https://malariaatlas.org/).
More details and example analyses can be found in the [published paper)[(<https://malariajournal.biomedcentral.com/articles/10.1186/s12936-018-2500-5>).
## Available Data:
The data can be explored at [https://data.malariaatlas.org/maps](https://data.malariaatlas.org/maps).
### List Versions Functions
The list version functions are used to list the available versions of different datasets, and all return a data.frame with a single column for version. These versions can be passed to functions such as `listShp`, `listSpecies`, `listPRPointCountries`, `listVecOccPointCountries`, `getPR`, `getVecOcc` and `getShp`.
Use:
- `listPRPointVerions()` to see the available versions for PR point data, which can then be used in `listPRPointCountries` and `getPR`.
- `listVecOccPointVersions()` to see the available versions for vector occurrence data, which can then be used in `listSpecies`, `listVecOccPointCountries` and `getVecOcc`.
- `listShpVersions()` to see the available versions for admin unit shape data, which can then be used in `listShp` and `getShp`.
```{r results = "hide", message = FALSE}
listPRPointVersions()
```
```{r results = "hide", message = FALSE}
listVecOccPointVersions()
```
```{r results = "hide", message = FALSE}
listShpVersions()
```
### List Countries and Species Functions
To list the countries where there is available data for PR points or vector occurrence points, use:
- `listPRPointCountries()` for PR points
- `listVecOccPointCountries()` for vector occurrence points
To list the species available for vector point data use `listSpecies()`
All three of these functions can optionally take a version parameter (which can be found with the list versions functions). If you choose not to provide a version, the most recent version of the relevant dataset will be selected by default.
```{r results = "hide", message = FALSE}
listPRPointCountries(version = "202206")
```
```{r results = "hide", message = FALSE}
listVecOccPointCountries(version = "201201")
```
```{r results = "hide", message = FALSE}
listSpecies(version = "201201")
```
### List Administrative Units
To list administrative units for which shapefiles are stored on the MAP geoserver, use `listShp()`. Similar to the list countries and species functions, this function can optionally take a version.
```{r results = "hide", message = FALSE}
listShp(version = "202206")
```
### List Raster Function
`listRaster()` gets minimal information on all available rasters. It returns a data.frame with several columns for each raster such as dataset_id, title, abstract, min_raster_year and max_raster_year. The dataset_id can then be used in `getRaster` and `extractRaster`.
```{r results = "hide", message = FALSE}
listRaster()
```
### Is Available Functions
`isAvailable_pr` confirms whether or not PR survey point data is available to download for a specified country, ISO3 code or continent.
Check whether PR data is available for Madagascar:
```{r results = "hide", message = FALSE}
isAvailable_pr(country = "Madagascar")
```
Check whether PR data is available for the United States of America by ISO code:
```{r results = "hide", message = FALSE}
isAvailable_pr(ISO = "USA")
```
Check whether PR data is available for Asia:
```{r results = "hide", message = FALSE}
isAvailable_pr(continent = "Asia")
```
`isAvailable_vec` confirms whether or not vector survey point data is available to download for a specified country, ISO3 code or continent.
Check whether vector data is available for Myanmar:
```{r results = "hide", message = FALSE}
isAvailable_vec(country = "Myanmar")
```
Check whether vector data is available for multiple countries:
```{r results = "hide", message = FALSE}
isAvailable_vec(country = c("Nigeria", "Ethiopia"))
```
You can also pass these functions a dataset version. If you don't they will default to using the most recent version.
```{r results = "hide", message = FALSE}
isAvailable_pr(country = "Madagascar", version = "202206")
```
## Downloading & Visualising Data:
### get\* functions & autoplot methods
### Parasite Rate Survey Points
`getPR()` downloads all publicly available PR data points for a specified location (country, ISO, continent or extent) and plasmodium species (Pf, Pv or BOTH) and returns this as a dataframe with the following format:
```{r message = FALSE, warning = FALSE, results = "hide"}
MDG_pr_data <- getPR(country = "Madagascar", species = "both")
```
```{r echo = FALSE}
tibble::glimpse(MDG_pr_data)
```
```{r message = FALSE}
Africa_pvpr_data <- getPR(continent = "Africa", species = "Pv")
```
```{r message = FALSE}
Extent_pfpr_data <- getPR(extent = rbind(c(-2.460181, 13.581921), c(-3.867188, 34.277344)), species = "Pf")
```
You can also pass this function a dataset version. If you don't it will default to using the most recent version.
```{r message = FALSE}
MDG_pr_data_202206 <- getPR(country = "Madagascar", species = "both", version = "202206")
```
`autoplot.pr.points` configures autoplot method to enable quick mapping of the locations of downloaded PR points.
```{r message = FALSE, warning = FALSE, results = "hide"}
autoplot(MDG_pr_data)
```
A version without facetting is also available.
```{r message = FALSE, warning = FALSE, results = "hide"}
autoplot(MDG_pr_data,
facet = FALSE)
```
### Vector Survey Points
`getVecOcc()` downloads all publicly available Vector survey points for a specified location (country, ISO, continent or extent) and species (options for which can be found with `listSpecies`) and returns this as a dataframe with the following format:
```{r message = FALSE, warning = FALSE, results = "hide"}
MMR_vec_data <- getVecOcc(country = "Myanmar")
```
```{r echo = FALSE}
tibble::glimpse(MMR_vec_data)
```
You can also pass this function a dataset version. If you don't it will default to using the most recent version.
```{r message = FALSE, warning = FALSE, results = "hide"}
MMR_vec_data_201201 <- getVecOcc(country = "Myanmar", version = "201201")
```
`autoplot.vector.points` configures autoplot method to enable quick mapping of the locations of downloaded vector points.
```{r message = FALSE, warning = FALSE, results = "hide"}
autoplot(MMR_vec_data)
```
N.B. Facet-wrapped option is also available for species stratification.
```{r message = FALSE, warning = FALSE, results = "hide"}
autoplot(MMR_vec_data,
facet = TRUE)
```
### Shapefiles
`getShp()` downloads a shapefile for a specified country (or countries) and returns this as a simple feature object.
```{r message = FALSE}
MDG_shp <- getShp(ISO = "MDG", admin_level = c("admin0", "admin1"))
```
```{r echo = FALSE}
tibble::glimpse(MDG_shp)
```
`autoplot.sf` configures autoplot method to enable quick mapping of downloaded shapefiles.
```{r message = FALSE}
autoplot(MDG_shp)
```
N.B. Facet-wrapped option is also available for species stratification.
```{r message = FALSE, warning = FALSE, results = "hide"}
autoplot(MDG_shp,
facet = TRUE,
map_title = "Example of facetted shapefiles.")
```
### Modelled Rasters
`getRaster()`downloads publicly available MAP rasters for a specific dataset_id & year, clipped to a given bounding box or shapefile
```{r message = FALSE, warning = FALSE, results = "hide"}
MDG_shp <- getShp(ISO = "MDG", admin_level = "admin0")
MDG_PfPR2_10 <- getRaster(dataset_id = "Explorer__2020_Global_PfPR", shp = MDG_shp, year = 2013)
```
`autoplot.SpatRaster` & `autoplot.SpatRasterCollection` configures autoplot method to enable quick mapping of downloaded rasters.
```{r message = FALSE}
p <- autoplot(MDG_PfPR2_10, shp_df = MDG_shp)
```
### Combined visualisation
By using the above tools along with ggplot, simple comparison figures can be easily produced.
```{r message = FALSE, warning = FALSE, results = "hide"}
MDG_shp <- getShp(ISO = "MDG", admin_level = "admin0")
MDG_PfPR2_10 <- getRaster(dataset_id = "Explorer__2020_Global_PfPR", shp = MDG_shp, year = 2013)
p <- autoplot(MDG_PfPR2_10, shp_df = MDG_shp, printed = FALSE)
pr <- getPR(country = c("Madagascar"), species = "Pf")
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 + Modelled PfPR 2-10 in Madagascar in 2013")
```
Similarly for vector survey data
```{r message = FALSE, warning = FALSE, results = "hide"}
MMR_shp <- getShp(ISO = "MMR", admin_level = "admin0")
MMR_An_dirus <- getRaster(dataset_id = "Explorer__2010_Anopheles_dirus_complex", shp = MMR_shp)
p <- autoplot(MMR_An_dirus, shp_df = MMR_shp, printed = FALSE)
vec <- getVecOcc(country = c("Myanmar"), species = "Anopheles dirus")
p[[1]] +
geom_point(data = vec, aes(longitude, latitude, colour = species))+
scale_colour_manual(values = "black", name = "Vector survey locations")+
scale_fill_distiller(name = "Predicted distribution of An. dirus complex", palette = "PuBuGn", direction = 1)+
ggtitle("Vector Survey points\n + The predicted distribution of An. dirus complex")
```
## Installation
### Latest stable version from CRAN
Just install using `install.packages("malariaAtlas")` or using the package manager in RStudio.
### Latest version from github
While this version is not as well-tested, it may include additional bugfixes not in the stable CRAN version. Install the `devtools` package and then install using `devtools::install_github('malaria-atlas-project/malariaAtlas')`