library(tidyverse)
## ── Attaching packages ────────────────────────────────────────────────── tidyverse 1.3.0 ──
## ✓ ggplot2 3.3.0     ✓ purrr   0.3.4
## ✓ tibble  3.0.1     ✓ dplyr   0.8.5
## ✓ tidyr   1.1.0     ✓ stringr 1.4.0
## ✓ readr   1.3.1     ✓ forcats 0.5.0
## ── Conflicts ───────────────────────────────────────────────────── tidyverse_conflicts() ──
## x dplyr::filter() masks stats::filter()
## x dplyr::lag()    masks stats::lag()
library(ggplot2)
library(malariaAtlas)
theme_set(theme_light()) 
malawi.pr<-tbl_df(malariaAtlas::getPR(country = "Malawi",species = "Both")) %>% 
  filter(!is.na(pr))
## Creating list of countries for which MAP data is available, please wait...
## Confirming availability of PR data for: Malawi...
## PR points are available for Malawi.
## Attempting to download PR point data for Malawi ...
## Data downloaded for Malawi.
## NOTE: All available data for this query was downloaded for both species,
##  but there are no PR points for P. vivax in this region in the MAP database. 
## To check endemicity patterns or to contribute data, visit malariaatlas.org OR email us at map@bdi.ox.ac.uk.
view(malawi.pr)
malawi.pr %>% 
  group_by(year_start) %>% 
  summarise(examined=sum(examined),
            positive=sum(positive),
            studies=n()) %>% 
  mutate(pr=positive/examined) %>% 
  ggplot(aes(year_start,pr))+
  geom_line()

malawi.pr %>% 
  mutate(decade=10*(year_start %/% 10)) %>% 
  arrange(pr) %>% 
  ggplot(aes(longitude,latitude,color= pr))+
  geom_point()+
  coord_map('polyconic')+
  borders("world",regions = "Malawi")+
  scale_color_gradient2(low = "blue", high = "red", 
                        midpoint = .5, labels= scales::percent_format())+
  facet_wrap(~decade)+
  theme_void()+
  labs(color="Prevalance")