Created
January 8, 2022 20:09
-
-
Save MJacobs1985/7a64811c78e0f71057625cd64edaa865 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| library(readxl) | |
| library(ggplot2) | |
| library(viridis) | |
| library(tidyverse) | |
| UK <- read_excel("referencetable.xlsx", sheet = "Table 7", skip = 4, n_max = 350) | |
| UK$Mortality.age.std=as.numeric(UK$Mortality.age.std) | |
| UK$Lower.limit=as.numeric(UK$Lower.limit) | |
| UK$Upper.limit=as.numeric(UK$Upper.limit) | |
| mynamestheme=theme(plot.title=element_text(face="bold",size=(15))) | |
| UK.covid <- read_excel("referencetable.xlsx", sheet = "Table 5", skip = 4, n_max = 350) | |
| UK.covid$Mortality.age.std=as.numeric(UK.covid$Mortality.age.std) | |
| UK.covid$Lower.limit=as.numeric(UK.covid$Lower.limit) | |
| UK.covid$Upper.limit=as.numeric(UK.covid$Upper.limit) | |
| UK.non.covid <- read_excel("referencetable.xlsx", sheet = "Table 6", skip = 4, n_max = 350) | |
| UK.non.covid$Mortality.age.std=as.numeric(UK.non.covid$Mortality.age.std) | |
| UK.non.covid$Lower.limit=as.numeric(UK.non.covid$Lower.limit) | |
| UK.non.covid$Upper.limit=as.numeric(UK.non.covid$Upper.limit) | |
| UK[UK$Number.deaths=="<3",]$Number.deaths=1.5 | |
| UK[UK$Number.deaths=="1.5",]$Unreliable="u" | |
| UK$Number.deaths=as.numeric(UK$Number.deaths) | |
| select=UK$Vaccination.status!="Unvaccinated" | |
| UK_all_deaths=aggregate(UK[select,]$Number.deaths,by=list(Age.group=UK[select,]$Age.group,Month=UK[select,]$Month), FUN=sum) | |
| UK_all_person.years=aggregate(UK[select,]$Person.years,by=list(Age.group=UK[select,]$Age.group,Month=UK[select,]$Month), FUN=sum) | |
| UK_all_vax=UK_all_deaths | |
| UK_all_vax$Number.deaths=UK_all_vax$x | |
| UK_all_vax$Person.years=UK_all_person.years$x | |
| UK_all_vax$Mortality.std=UK_all_vax$Number.deaths/UK_all_vax$Person.years*100000 | |
| UK$Mortality.std=UK$Number.deaths/UK$Person.years*100000 | |
| UK_all_vax$Unvaccinated.Mortality.std=UK[UK$Vaccination.status=="Unvaccinated",]$Mortality.std | |
| UK_all_vax$Unvaccinated.Person.years=UK[UK$Vaccination.status=="Unvaccinated",]$Person.years | |
| UK.non.covid$Covid="No" | |
| UK.covid$Covid="Yes" | |
| UK.combined<-rbind(UK.non.covid,UK.covid) | |
| UK.combined.sum<-UK.combined %>% | |
| group_by(Age.group,Vaccination.status,Covid) %>% | |
| summarize(mean_mort = sum(Mortality.age.std, na.rm = TRUE)) | |
| ggplot(UK.combined.sum, aes(x=Age.group, | |
| fill=as.numeric(mean_mort), | |
| y=Vaccination.status))+ | |
| facet_wrap(~Covid)+ | |
| scale_fill_viridis_c(option="C")+ | |
| geom_tile() + theme_bw() + guides(fill=guide_legend(title="Mortality Age Standard")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment