#d<-read.csv("https://download.ons.gov.uk/downloads/datasets/weekly-deaths-local-authority/editions/time-series/versions/13.csv")
d<-read.csv("https://download.beta.ons.gov.uk/downloads/datasets/weekly-deaths-local-authority/editions/time-series/versions/13.csv")
d$Week<-aqm::clean(d$Week)
d %>% filter(RegistrationOrOccurrence =="Occurrences") ->d
d %>% group_by(Week, CauseOfDeath) %>% summarise(deaths=sum(v4_0)) %>% ggplot(aes(x=Week,y=deaths,col=CauseOfDeath)) +geom_line()

d %>% filter(PlaceOfDeath %in% c("Hospital", "Care home", "Home")) %>% group_by(Week, CauseOfDeath, PlaceOfDeath)  %>% summarise(deaths=sum(v4_0)) ->d2
aqm::dt(d2)
ggplot(d2,aes(x=Week,y=deaths,colour=CauseOfDeath)) +geom_line() +facet_wrap("PlaceOfDeath")

library(dygraphs)
d %>% group_by(Week, CauseOfDeath) %>% summarise(deaths=sum(v4_0)) %>% pivot_wider(names_from = CauseOfDeath,values_from = deaths) %>% dygraph()
library(dygraphs)
d %>% filter(CauseOfDeath=="All causes") %>% filter(PlaceOfDeath=="Hospital") %>% group_by(Week, Geography) %>% summarise(deaths=sum(v4_0))%>% pivot_wider(names_from = Geography,values_from = deaths) %>% dygraph() %>% dyLegend(show="never")
d %>% filter(CauseOfDeath=="COVID 19") %>% filter(PlaceOfDeath=="Hospital") %>% group_by(Week, Geography) %>% summarise(deaths=sum(v4_0)) %>% pivot_wider(names_from = Geography,values_from = deaths) %>% dygraph() %>% dyLegend(show="never")
d %>% filter(CauseOfDeath=="All causes") %>% filter(PlaceOfDeath=="Home") %>% group_by(Week, Geography) %>% summarise(deaths=sum(v4_0)) %>% pivot_wider(names_from = Geography,values_from = deaths) %>% dygraph() %>% dyLegend(show="never")