Filter only Montana schools, remove non-plausible mmr values, and select distinct cases
mt_meas<-measles %>%
filter(state == "Montana") %>%
filter(mmr > 0) %>%
distinct(index,state,name,county,enroll,mmr, .keep_all = T)
mt_meas %>%
head(8)
## # A tibble: 8 x 16
## index state year name type city county district enroll mmr overall xrel
## <dbl> <chr> <chr> <chr> <chr> <chr> <chr> <lgl> <dbl> <dbl> <dbl> <lgl>
## 1 1 Mont… 2017… Acad… <NA> <NA> Silve… NA 64 100 -1 NA
## 2 2 Mont… 2017… Anna… <NA> <NA> Glaci… NA 105 100 -1 NA
## 3 3 Mont… 2017… Ashl… <NA> <NA> Roseb… NA 75 100 -1 NA
## 4 4 Mont… 2017… Aton… <NA> <NA> Yello… NA 26 100 -1 NA
## 5 5 Mont… 2017… Big … <NA> <NA> Casca… NA 38 100 -1 NA
## 6 6 Mont… 2017… Blac… <NA> <NA> Glaci… NA 76 100 -1 NA
## 7 7 Mont… 2017… Chil… <NA> <NA> Misso… NA 318 100 -1 NA
## 8 8 Mont… 2017… Crow… <NA> <NA> Big H… NA 315 100 -1 NA
## # … with 4 more variables: xmed <dbl>, xper <dbl>, lat <dbl>, lng <dbl>
Load in spatial datasets
# load in world and state sf
world <- ne_countries(scale = "medium", returnclass = "sf")
states <- st_as_sf(map("state", plot = FALSE, fill = TRUE))
# load in county data
load(url("https://github.com/mgimond/ES218/blob/gh-pages/Data/counties48.RData?raw=true"))
Seperate ID into state and county names
Filter only Montana data
Change the case of “county” so that it matches measles data formatting
mtcounties<-cnty %>%
separate(col=ID, into = c("state","county"),sep = ",", remove = F) %>%
filter(state=="montana") %>%
mutate(county = snakecase::to_upper_camel_case(county))
#mtcounties %>%
# head(8)
# summarize measles data by county
mt1<-mt_meas %>%
filter(name != "West Valley School Prek-6") %>% # extreme outlier, something wrong with this datapoint
group_by(county) %>%
mutate(xmt = (xrel + xmed + xper)) %>%
mutate(totalvacc = enroll*(mmr/100)) %>%
mutate(unvacc = enroll-totalvacc) %>%
summarise(mean_mmr=mean(mmr,na.rm = T), sum_exmt = sum(xrel,na.rm = T), total_unvacc = sum(unvacc,na.rm = T))
# join summarized measles data to county spatial data
mt2<-mt1 %>%
mutate(round_unvacc = paste(round(mean_mmr,0),"%",sep = "")) %>%
left_join(mtcounties, by = "county")
# create wesanderson palette
pal <- wesanderson::wes_palette("Zissou1", 100, type = "continuous")
# create plot of mean mmr vaccination rate by county
mmrplot<-ggplot(data = world) + geom_sf() + geom_sf(data = states) + geom_sf(data=mtcounties) +
geom_sf(data=mt2$geometry, aes(fill=mt2$mean_mmr)) +
coord_sf(xlim = c(min(mt_meas$lng,na.rm = T)-1,max(mt_meas$lng,na.rm = T)+1),
ylim = c(min(mt_meas$lat,na.rm = T)-1, max(mt_meas$lat,na.rm = T)+1),expand = FALSE) +
LGCtheme + scale_x_continuous(breaks=seq(-116,-104,4)) +
scale_y_continuous(breaks=seq(43,49,3)) +
scale_fill_gradientn(colours = rev(pal)) +
labs(fill="", x="",y="") +
theme(legend.position = c(0.1, 0.2), legend.background = element_blank(), legend.title = element_text(size=10))
# create plot of number unvaccinated by county
unvaccplot<-ggplot(data = world) + geom_sf() + geom_sf(data = states) + geom_sf(data=mtcounties) +
geom_sf(data=mt2$geometry, aes(fill=(mt2$total_unvacc))) +
coord_sf(xlim = c(min(mt_meas$lng,na.rm = T)-1,max(mt_meas$lng,na.rm = T)+1),
ylim = c(min(mt_meas$lat,na.rm = T)-1, max(mt_meas$lat,na.rm = T)+1),expand = FALSE) +
LGCtheme + scale_x_continuous(breaks=seq(-116,-104,4)) +
scale_y_continuous(breaks=seq(43,49,3)) +
scale_fill_gradientn(colours = pal) +
labs(fill="", x="",y="") +
theme(legend.position = c(0.1, 0.2), legend.background = element_blank(), legend.title = element_text(size=10))
| County | Mean MMR Vacc | Total Exemptions | Total Unvacc |
|---|---|---|---|
| Flathead | 91.15812 | 0 | 721.0298 |
| Gallatin | 90.26943 | 0 | 428.0193 |
| Ravalli | 79.99909 | 0 | 405.9783 |
| Hill | 87.55222 | 0 | 325.9764 |
| Missoula | 95.30806 | 0 | 284.9955 |
| Yellowstone | 96.95689 | 0 | 278.9469 |
| Lake | 89.31176 | 0 | 255.0102 |
| Toole | 73.20500 | 0 | 249.9804 |
| Cascade | 96.88862 | 0 | 158.9801 |
| Lincoln | 82.93333 | 0 | 151.0146 |