library(COVID19)
#d <- covid19(country="India",level=2)
#save(d,file="india.rda")
load("india.rda")
d %>% filter(date> Sys.Date()-90) -> d
d %>% group_by(administrative_area_level_2) -> d
d %>%arrange(date) %>% mutate(New_cases = confirmed - lag(confirmed, default = first(confirmed))) -> d
d %>% mutate(New_deaths = deaths - lag(deaths, default = first(deaths))) %>% arrange(deaths) -> d
d %>% mutate(New_tests = tests - lag(tests, default = first(tests))) %>% arrange(tests) -> d
toupper(unique(d$administrative_area_level_2)) -> states
d1<- data.frame(state=states)
d1$state<-toupper(d1$state)
library(readr)
dd <- read_csv("india-districts-census-2011.csv")
dd %>% group_by(`State name`) %>% summarise(pop=sum(Population))-> dd
names(dd)<-c("state", "pop")
dd$state<-toupper(dd$state)
merge(dd,d1)-> dd
d$state <- toupper(d$administrative_area_level_2)
merge(d,dd)-> d
d %>% filter(state %in% states[1:10]) %>%
ggplot(aes(x=date,y =New_cases/(pop/1000000))) +geom_line() +facet_wrap(~administrative_area_level_2,scales = "free")
`
d %>% filter(state %in% states[11:20]) %>%
ggplot(aes(x=date,y =New_cases/(pop/1000000))) +geom_line() +facet_wrap(~administrative_area_level_2,scales = "free")
`
d %>% filter(state %in% states[21:31]) %>%
ggplot(aes(x=date,y =New_cases/(pop/1000000))) +geom_line() +facet_wrap(~state,scales = "free")
`
d %>% group_by(state) %>% summarise(peak=round(max(New_cases/(pop/1000000))))->pp
library(rnaturalearth)
library(RColorBrewer)
colors <- brewer.pal(7, "RdYlGn")[7:1]
ind<-rnaturalearth::ne_states(country="India", ret="sf")[,9]
ind$state<-toupper(ind$name)
ind<-merge(ind,pp)
mapview(ind, zcol="peak",legend=TRUE, col.regions=colors, at=c(0,50,100,200,500,1000,5000))