# Warning: # Script is designed to work with R for windows # The script should now also run on Linux and Mac script # (encoding issues fixed). ################################################### ##Eventually install the following packages #install.packages("zoo") #install.packages("RColorBrewer") #install.packages("plyr") #install.packages("readxl") #install.packages("httr") #install.packages("XML") #install.packages("htmltab") #install.packages("reshape2") library(reshape2) library(htmltab) library(purrr) library(httr) library(plyr) library(readxl) library(zoo) library(RColorBrewer) darkcols <- c(brewer.pal(8, "Dark2"),brewer.pal(8, "Paired")) ################################################### ################################################### # Useful functions simplelag <-function(x,by=NULL,mylag=1,outside=NA) { myend<-length(x)- mylag if (!is.null(by)) { lby<-c(replicate(mylag,""),as.character(by[1:myend])) y0<-c(replicate(mylag,outside),x[1:myend]) y<-ifelse(as.character(by)==lby,y0,outside) } else { y<-c(replicate(mylag,outside),x[1:myend]) } } retain<-function(x,event,outside=NA) { indices <- c(1,which(event==TRUE), length(x)+1) values <- c(outside,x[event==TRUE]) y<- rep(values, diff(indices)) } ################################################### ################################################### # SOURCES FOR COVID19 ################################################### #World world<-read.csv("https://opendata.ecdc.europa.eu/covid19/casedistribution/csv") world_bis<-read.csv("https://covid.ourworldindata.org/data/ecdc/full_data.csv") world_region_cases<-read.csv("https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/time_series_covid19_confirmed_global.csv") world_region_deaths<-read.csv("https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/time_series_covid19_deaths_global.csv") world_region_recovered<-read.csv("https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/time_series_covid19_recovered_global.csv") world_beds<-read.csv("http://olivier.godechot.free.fr/hopfichiers/world_hospital_beds.csv", skip=4,header=TRUE,encoding="UTF-8") #Italian regions finish <- as.Date(Sys.Date()-1, format="%Y%m%d") start <- as.Date("20200224", format="%Y%m%d") length<-finish-start italy<-NULL for (i in 1:length) { datefile<-format(Sys.Date()-length+i,"%Y%m%d") url<-paste("https://raw.githubusercontent.com/pcm-dpc/COVID-19/master/dati-regioni/dpc-covid19-ita-regioni-",datefile,".csv",sep="") file<-read.csv(url) italy<-rbind.fill(italy,file) } pop_italy <- data.frame(map2("https://en.wikipedia.org/wiki/Regions_of_Italy", 2, htmltab,rm_nodata_cols = F)) colnames(pop_italy)<-c("Flag","Province","Status","Population","Population_share","Area","Area_share","Density","HDI", "Capital_city","President_color","President","Number_cities","Prov_met_cities") pop_italy_2 <- data.frame(map2("https://en.wikipedia.org/wiki/Trentino-Alto_Adige/S%C3%BCdtirol", 2, htmltab,rm_nodata_cols = F)) colnames(pop_italy_2)<-c("Province","Area","Population","Density") #Spanish regions spain<-read.csv("https://covid19.isciii.es/resources/serie_historica_acumulados.csv", encoding="latin1") pop_spain <- data.frame(map2("https://simple.wikipedia.org/wiki/Ranked_list_of_Spanish_autonomous_communities_by_population", 1, htmltab,rm_nodata_cols = F)) code_spain <- data.frame(map2("https://en.wikipedia.org/wiki/ISO_3166-2:ES", 1, htmltab,rm_nodata_cols = F)) colnames(pop_spain)<-c("Rank","Region","Population","Population_share","Density") colnames(code_spain)<-c("Code","Subdivision_name_es","Subdivision_name_en","Subdivision_category") #French regions and departments france<-read.csv("https://raw.githubusercontent.com/opencovid19-fr/data/master/dist/chiffres-cles.csv",encoding="UTF-8") # Original source for French population. Downloaded on my web site to increase spead. # url<-"https://www.insee.fr/fr/statistiques/fichier/3545833/ensemble.xls" # GET(url, write_disk(tf <- tempfile(fileext = ".xls"))) # france_pop <- read_excel(tf, 2L,skip=7) # write.csv(france_pop,file="france_pop.csv",fileEncoding="UTF-8") france_pop<-read.csv("http://olivier.godechot.free.fr/hopfichiers/france_pop.csv",encoding="UTF-8") colnames(france_pop)<-c("X","code_region","nom_region","code_departement","nom_departement","nombre_arrondissements" ,"nombre_cantons","nombre_communes","population_municipale","population_totale") france_reg_pop<-as.data.frame.table(tapply(france_pop$population_totale,france_pop$code_region,sum)) colnames(france_reg_pop)<-c("code","population") france_dep_pop<-as.data.frame.table(tapply(france_pop$population_totale,france_pop$code_departement,sum)) colnames(france_dep_pop)<-c("code","population") france_dep_pop2<-as.data.frame(map2("https://fr.wikipedia.org/wiki/Liste_des_d%C3%A9partements_fran%C3%A7ais_class%C3%A9s_par_population_et_superficie",1, htmltab,rm_nodata_cols = F)) colnames(france_dep_pop2)[c(2,ncol(france_dep_pop2))]<-c("code","area") #Hospital Beds france_beds<-read.csv2("http://olivier.godechot.free.fr/hopfichiers/france_hospital_beds.csv", skip=6,header=TRUE,encoding="latin1") france_beds<-france_beds[,c(1,15,27)] colnames(france_beds)<-c("unit","beds2000","beds2012") #UK #UK country Cases and deaths uk_countries<-read.csv("https://raw.githubusercontent.com/tomwhite/covid-19-uk-data/master/data/covid-19-indicators-uk.csv") #UK Detailed Cases uk_cases<-read.csv("https://coronavirus.data.gov.uk/downloads/csv/coronavirus-cases_latest.csv") uk_deaths<-read.csv("https://coronavirus.data.gov.uk/downloads/csv/coronavirus-deaths_latest.csv") # #England Cases # url<-"https://fingertips.phe.org.uk/documents/Historic%20COVID-19%20Dashboard%20Data.xlsx" # GET(url, write_disk(tf <- tempfile(fileext = ".xlsx"))) # england_cases <- read_excel(tf,sheet = 5,skip=7) #England Deaths ukdate<-Sys.Date() m<-format(ukdate,"%m") d<-as.numeric(format(ukdate,"%d")) Y<-format(ukdate,"%Y") M<-c("January","February","March","April","May","June","July","August","September","October","November","December")[as.numeric(m)] url<-paste("https://www.england.nhs.uk/statistics/wp-content/uploads/sites/2/2020/",m,"/COVID-19-total-announced-deaths-",d, "-",M,"-",Y,".xlsx",sep="") url GET(url, write_disk(tf <- tempfile(fileext = ".xlsx"))) filesize<-file.size(tf) uk_start_new<-as.Date("2020-02-29") ndays<-as.numeric(ukdate-uk_start_new) if (filesize<197) { ukdate<-ukdate-1 m2<-format(ukdate,"%m") d2<-as.numeric(format(ukdate,"%d")) M<-c("January","February","March","April","May","June","July","August","September","October","November","December")[as.numeric(m2)] url<-paste("https://www.england.nhs.uk/statistics/wp-content/uploads/sites/2/2020/",m2,"/COVID-19-total-announced-deaths-",d2, "-",M,"-",Y,".xlsx",sep="") url GET(url, write_disk(tf <- tempfile(fileext = ".xlsx"))) filesize<-file.size(tf) ndays<-ndays-1 } england_deaths <- read_excel(tf,sheet = 3,skip=15) england_deaths_det <- read_excel(tf,sheet = 2,skip=15) # url<-paste("https://www.england.nhs.uk/statistics/wp-content/uploads/sites/2/2020/04/COVID-19-all-announced-deaths-15-April-2020.xlsx",sep="") # url<-paste("https://www.england.nhs.uk/statistics/wp-content/uploads/sites/2/2020/04/COVID-19-total-announced-deaths-14-April-2020.xlsx",sep="") # GET(url, write_disk(tf <- tempfile(fileext = ".xlsx"))) # filesize<-file.size(tf) # england_deaths_old <- read_excel(tf,sheet = 2,skip=15) # england_deaths_det_old <- read_excel(tf,sheet = 1,skip=15) # # uk_start_old<-as.Date("2020-02-29") # uk_end_old<-as.Date("2020-04-14") # ndays_old<-as.numeric(uk_end_old-uk_start_old) # #English population pop_england<-data.frame(map2("https://en.wikipedia.org/wiki/Regions_of_England", 5, htmltab,rm_nodata_cols = F)) pop_uk_country<-data.frame(map2("https://en.wikipedia.org/wiki/Countries_of_the_United_Kingdom_by_population", 1, htmltab,rm_nodata_cols = F)) #German regions germany<-read.csv("https://opendata.arcgis.com/datasets/dd4580c810204019a7b8eb3e0b329dd6_0.csv",encoding="UTF-8",stringsAsFactors = F) # pop_germany <- data.frame(map2("https://de.wikipedia.org/wiki/Land_(Deutschland)", 1, htmltab,rm_nodata_cols = F)) # colnames(pop_germany)<-c("Wappen","Land","Kurzel","Hauptstadt","Beitritt_zum_Bund","Regierungs_chef", # "Regierungs_partei","Bundesrats_stimmen","Flache","Einwohner","Einwohner_km2", # "Auslander","Sprachen") pop_germany <- read.csv2("https://www.regionalstatistik.de/genesisws/downloader/00/12111-01-01-4_00.csv" ,encoding="latin",skip=9,stringsAsFactors = FALSE) colnames(pop_germany)<-c("region_id","region","population","males","females", "germans","male_germans","female_germans", "foreigners","male_foreigners","female_foreigners") pop_germany$population<-as.numeric(pop_germany$population) pop_germany$region_id<-as.numeric(gsub(",",".",pop_germany$region_id)) area_germany <- read.csv2("https://www.regionalstatistik.de/genesisws/downloader/00/11111-01-01-4_00.csv" ,encoding="latin",skip=5,stringsAsFactors = FALSE) colnames(area_germany)<-c("date_info","region_id","region","area") area_germany$area<-as.numeric(gsub(",",".",area_germany$area)) area_germany$region_id<-as.numeric(gsub(",",".",area_germany$region_id)) pop_germany<-merge(pop_germany,area_germany[,c("region_id","area")],by="region_id",all=TRUE) pop_germany$density<-pop_germany$population/pop_germany$area #USA States usa<-read.csv("https://github.com/nytimes/covid-19-data/raw/master/us-states.csv",encoding="UTF-8") usa_county<-read.csv("https://raw.githubusercontent.com/nytimes/covid-19-data/master/us-counties.csv",encoding="UTF-8") # url<-"https://www2.census.gov/programs-surveys/popest/tables/2010-2019/state/detail/SCPRC-EST2019-18+POP-RES.xlsx" # GET(url, write_disk(tf <- tempfile(fileext = ".xlsx"))) # usa_pop <- read_excel(tf,skip=8) # colnames(usa_pop)<-c("state","population","pop18_plus","share_pop18_plus") # usa_pop$state<-ifelse(usa_pop$state!="Puerto Rico",substr(usa_pop$state,2,nchar(usa_pop$state)),usa_pop$state) # usa_pop<-na.omit(usa_pop) # write.csv(usa_pop,file="usa_pop.csv",fileEncoding = "UTF-8") usa_pop<-read.csv("http://olivier.godechot.free.fr/hopfichiers/usa_pop.csv",encoding = "UTF-8") #China Population china_pop<-data.frame(map2("https://en.wikipedia.org/wiki/List_of_Chinese_administrative_divisions_by_population", 4, htmltab,rm_nodata_cols = F)) colnames(china_pop)<-c("Administrative_Division","Population","Comparable_country","Urban_pop","Rural_pop","Ref") #Australia Population australia_pop<-data.frame(map2("https://en.wikipedia.org/wiki/States_and_territories_of_Australia", 4, htmltab,rm_nodata_cols = F)) str(australia_pop) colnames(australia_pop)<-c("Flag","State_name","Abbrev","ISO","Capital","Population","area","Governor","Premier_color","Premier") #Canada Population canada_pop<-data.frame(map2("https://en.wikipedia.org/wiki/List_of_Canadian_provinces_and_territories_by_population", 1, htmltab,rm_nodata_cols = F)) colnames(canada_pop)<-c("Pop_rank","Name","Population_2016","Population_2016_share","Growth_10_16","Area","density","House_Comons_seats","House_Comons_seats_share", "Population_2020","Population_2020_share","Growth_16_20") ###################################################################### # Provisional storage world_0<-world italy_0<-italy spain_0<-spain france_0<-france germany_0<-germany usa_0<-usa ##################################################################### ################################################### # Graphical parameters my_col<-darkcols my_pch<-c(0:25) ################################################### #Tresholds for counting days ################################################### #World nations total cases and total death thresholds world_case_threshold<-2000 world_death_threshold<-100 world_population_threshold<-1000000 world_cases_2_pop_threshold<-5 world_death_2_pop_threshold<-1 #china region total cases and total deaths thresholds china_case_threshold<-1000 china_death_threshold<-10 china_population_threshold<-100000 china_cases_2_pop_threshold<-5 china_death_2_pop_threshold<-1 #Italy region total cases and total deaths thresholds italy_case_threshold<-500 italy_death_threshold<-50 italy_population_threshold<-100000 italy_cases_2_pop_threshold<-5 italy_death_2_pop_threshold<-1 #Spain region total cases and total deaths thresholds spain_case_threshold<-500 spain_death_threshold<-50 spain_population_threshold<-100000 spain_cases_2_pop_threshold<-5 spain_death_2_pop_threshold<-1 #French regions Death threshold france_reg_case_threshold<-500 france_reg_death_threshold<-50 france_reg_population_threshold<-100000 france_reg_cases_2_pop_threshold<-5 france_reg_death_2_pop_threshold<-1 #French Departments Death threshold france_dep_case_threshold<-500 france_dep_death_threshold<-50 france_dep_population_threshold<-100000 france_dep_cases_2_pop_threshold<-5 france_dep_death_2_pop_threshold<-1 #UK Death threshold uk_case_threshold<-500 uk_death_threshold<-50 uk_population_threshold<-100000 uk_cases_2_pop_threshold<-5 uk_death_2_pop_threshold<-1 #Germany region total cases and total deaths thresholds germany_case_threshold<-500 germany_death_threshold<-50 germany_population_threshold<-100000 germany_cases_2_pop_threshold<-2 germany_death_2_pop_threshold<-0.5 #Germany detailed region total cases and total deaths thresholds germany_det_case_threshold<-500 germany_det_death_threshold<-20 #USA region total cases and total deaths thresholds usa_case_threshold<-2000 usa_death_threshold<-100 usa_population_threshold<-100000 usa_cases_2_pop_threshold<-5 usa_death_2_pop_threshold<-1 #australia region total cases and total deaths thresholds australia_case_threshold<-100 australia_death_threshold<-5 australia_population_threshold<-100000 australia_death_2_pop_threshold<-0.05 australia_cases_2_pop_threshold<-0.5 #canada region total cases and total deaths thresholds canada_case_threshold<-100 canada_death_threshold<-5 canada_population_threshold<-100000 canada_death_2_pop_threshold<-0.1 canada_cases_2_pop_threshold<-0.5 ################################################### ############################################################ # DATA MANIPULATION ############################################################ ############################################################ world<-world_0 italy<-italy_0 spain<-spain_0 france<-france_0 germany<-germany_0 usa<-usa_0 ############################################################## #World world$location<-world$countriesAndTerritories world$new_cases<-world$cases world$new_deaths<-world$deaths world$population<-world$popData2018 world$date<-as.Date(world[,1], format="%d/%m/%Y") world<-world[order(world$location,world$date),] world$total_cases<-ave(world$new_cases,world$location,FUN=function(x) cumsum(x)) world$total_deaths<-ave(world$new_deaths,world$location,FUN=function(x) cumsum(x)) world$cases_2_pop<-10000*world$total_cases/world$population world$deaths_2_pop<-100000*world$total_deaths/world$population world_region_1<-reshape(world_region_cases, varying = list(5:ncol(world_region_cases)), times=colnames(world_region_cases)[5:ncol(world_region_cases)], v.names = "total_cases",direction = "long") world_region_2<-reshape(world_region_deaths, varying = list(5:ncol(world_region_deaths)), times=colnames(world_region_deaths)[5:ncol(world_region_deaths)], v.names = "total_deaths",direction = "long") world_region_3<-reshape(world_region_recovered, varying = list(5:ncol(world_region_recovered)), times=colnames(world_region_recovered)[5:ncol(world_region_recovered)], v.names = "total_recovered",direction = "long") world_region<-merge(world_region_1,world_region_2[,c("Province.State","Country.Region","time","total_deaths")],by=c("Province.State","Country.Region","time"),all=TRUE) world_region<-merge(world_region,world_region_3[,c("Province.State","Country.Region","time","total_recovered")],by=c("Province.State","Country.Region","time"),all=TRUE) world_region$date<-as.Date(gsub("X","",world_region$time),format="%m.%d.%y") world_region<-world_region[order(world_region$Country.Region,world_region$Province.State,world_region$date),] world_region$ident<-as.numeric(factor(paste(world_region$Country.Region,world_region$Province.State))) world_region$location<-world_region$Province.State rownames(world_region)<-NULL world_region$new_cases<-world_region$total_cases-simplelag(world_region$total_cases,by=world_region$ident,outside=0) world_region$new_deaths<-world_region$total_deaths-simplelag(world_region$total_deaths,by=world_region$ident,outside=0) world_region$new_recovered<-world_region$total_recovered-simplelag(world_region$total_recovered,world_region$ident,outside=0) world_region$active_cases<-world_region$total_cases-world_region$total_deaths-world_region$total_recovered world_region$new_active_cases<-world_region$new_cases-world_region$new_deaths-world_region$new_recovered recovered<-as.data.frame.table(tapply(world_region_3$total_recovered,list(world_region_3$Country.Region,world_region_3$time),sum,na.rm=TRUE)) colnames(recovered)<-c("location","time","total_recovered") recovered$date<-as.Date(gsub("X","",recovered$time),format="%m.%d.%y") str(recovered) #World hospital beds world_beds2<-reshape(world_beds[,c(1,5:64)],direction="long", idvar = "Country",#ids="Country.Name", varying=2:61,v.names="beds") world_beds2$year<-world_beds2$time+1959 colnames(world_beds2)[1]<-"location" str(world_beds2) row.names(world_beds2)<-NULL world_beds2$last<-ave((1-is.na(world_beds2$beds))*world_beds2$year,world_beds2$location,FUN=max) world_beds3<-world_beds2[world_beds2$year == world_beds2$last,] world_beds4<-world_beds2[world_beds2$year == world_beds2$last-10,] world_beds_evol10<-merge(world_beds3[,c("location","year","beds")],world_beds4[,c("location","beds")],by=c("location")) colnames(world_beds_evol10)<-c("location","lastmeasure","beds","beds_10") world_beds_evol10$beds_evol<-world_beds_evol10$beds-world_beds_evol10$beds_10 world_beds_evol10$r_beds_evol<-world_beds_evol10$beds_evol/world_beds_evol10$beds_10 world$location<-gsub("_"," ",world$location) world<-merge(world,world_beds_evol10,by="location",all.x=TRUE) world<-merge(world,recovered,by=c("location","date"),all.x=TRUE) world<-world[order(world$location,world$date),] row.names(world)<-NULL world$new_recovered<-world$total_recovered-simplelag(world$total_recovered,world$location,outside=0) world$active_cases<-world$total_cases-world$total_deaths-world$total_recovered world$new_active_cases<-world$new_cases-world$new_deaths-world$new_recovered world$nb_beds<-world$beds*world$population/1000 world$nb_beds_cuts<-(world$beds*world$population/1000)-(world$beds_10*world$population/1000) world$cases_per_beds<-(world$total_cases-world$total_deaths)/world$nb_beds world$cases_per_beds_cuts<--(world$total_cases-world$total_deaths)/world$nb_beds_cuts world$deaths_2_cases<-100*world$total_deaths/world$total_cases world$lastrecord<-(ave(world$date,world$location,FUN=max)==world$date)*1 world$active_cases_per_beds<-world$active_cases/world$nb_beds world$location[world$location=="United States of America"]<-"US" world$location[world$location=="United Kingdom"]<-"UK" #Italy italy$date<-as.Date(italy$data) italy$location<-italy$denominazione_regione italy$total_cases<-italy$totale_casi italy$new_cases<-italy$nuovi_positivi italy$total_deaths<-italy$deceduti italy<-italy[order(italy$location,italy$date),] italy$new_deaths<-italy$total_deaths-simplelag(italy$total_deaths,italy$location,outside=0) pop_italy$location<-pop_italy$Province pop_italy$location<-gsub("-"," ",pop_italy$location) pop_italy$location<-gsub("Tuscany","",pop_italy$location) pop_italy$location<-gsub("Sardinia","",pop_italy$location) pop_italy$location<-gsub("Sicily","",pop_italy$location) pop_italy$location<-gsub("Aosta Valley","",pop_italy$location) pop_italy$location<-gsub("Apulia","",pop_italy$location) pop_italy$location<-gsub("Lombardy","",pop_italy$location) pop_italy$location<-gsub("Piedmont","",pop_italy$location) pop_italy$location<-gsub("Emilia Romagna","Emilia-Romagna",pop_italy$location) pop_italy$population<-as.numeric(gsub(",","",as.character(pop_italy$Population))) pop_italy$density<-as.numeric(gsub(",","",as.character(pop_italy$Density))) pop_italy_2$location<-pop_italy_2$Province pop_italy_2$location<-gsub("Trentino","P.A. Trento",pop_italy_2$location) pop_italy_2$location<-gsub("South Tyrol","P.A. Bolzano",pop_italy_2$location) pop_italy_2$population<-as.numeric(gsub(",","",as.character(pop_italy_2$Population))) pop_italy_2$density<-as.numeric(gsub(",","",as.character(pop_italy_2$Density))) pop_italy_3<-rbind(pop_italy[,c("location","population","density")],pop_italy_2[,c("location","population","density")]) italy<-merge(italy,pop_italy_3[,c("location","population","density")],by="location",all.x=TRUE) italy$cases_2_pop<-10000*italy$total_cases/italy$population italy$deaths_2_pop<-100000*italy$total_deaths/italy$population italy<-italy[order(italy$location,italy$date),] #Spain spain$date<-as.Date(spain$FECHA, format="%d/%m/%Y") #paste(substr(spain$Fecha,7,10),substr(spain$Fecha,4,5),substr(spain$Fecha,1,2),sep="-") spain$code<-substr(spain$CCAA,1,2) pop_spain$location<-iconv(pop_spain$Region,"UTF-8","latin1") pop_spain$population<-as.numeric(gsub(",","",as.character(pop_spain$Population))) pop_spain$density<-as.numeric(gsub(",","",as.character(pop_spain$Density))) code_spain$location<-iconv(code_spain$Subdivision_name_en,"UTF-8","latin1") code_spain$location<-gsub("Chartered Community of ","",code_spain$location) code_spain$location<-gsub("Principality of ","",code_spain$location) code_spain$location<-gsub("Region of ","",code_spain$location) code_spain$code<-substr(code_spain$Code,4,5) pop_spain2<-merge(pop_spain[,c("location","population","density")],code_spain[,c("location","code")],by="location",all=TRUE) spain<-merge(spain,pop_spain2,by="code",all.x=TRUE) spain<-spain[order(spain$location,spain$date),] spain$total_cases<-spain$PCR. spain$hospitalization<-spain$Hospitalizados/spain$population spain$reanimation<-spain$UCI/spain$population spain$total_deaths<-spain$Fallecidos spain$death_approx<-ave(spain$total_deaths,spain$location,FUN=function(x) na.approx(x,na.rm=FALSE)) spain<-spain[order(spain$location,spain$date),] spain$new_cases<-spain$total_cases-simplelag(spain$total_cases,spain$location,outside=0) spain$new_deaths<-spain$total_deaths-simplelag(spain$total_deaths,spain$location,outside=0) View(spain) spain$hospitalization_evol<-spain$hospitalization-simplelag(spain$hospitalization,spain$location,outside=0) spain$reanimation_evol<-spain$reanimation-simplelag(spain$reanimation,spain$location,outside=0) spain$cases_2_pop<-10000*spain$total_cases/spain$population spain$deaths_2_pop<-100000*spain$total_deaths/spain$population spain<-spain[order(spain$location,spain$date),] #France france$location<-france$maille_nom france$total_deaths<-france$deces france$date<-as.Date(france$date) #french_beds france_beds$code_dep<-ifelse(substr(france_beds$unit,1,1)=="D",substr(france_beds$unit,2,4),NA) france_beds$code_dep<-ifelse(substr(france_beds$code_dep,3,4)==" ",substr(france_beds$code_dep,1,2),france_beds$code_dep) france_beds$code_reg<-ifelse(substr(france_beds$unit,1,1)=="R",substr(france_beds$unit,2,4),NA) france_beds$code_reg<-ifelse(substr(france_beds$code_reg,3,4)==" ",substr(france_beds$code_reg,1,2),france_beds$code_reg) #French regions france_reg<-france[france$granularite %in% "region",] france_reg<-france_reg[order(france_reg$location,france_reg$date,-france_reg$total_deaths),] france_reg$sel<-ave((france_reg$location !=""),paste(france_reg$location,france_reg$date),FUN=function(x) cumsum(x)) france_reg<-france_reg[france_reg$sel %in% 1,] row.names(france_reg)<-NULL france_reg$code<-substr(france_reg$maille_code,5,7) france_reg<-merge(france_reg,france_reg_pop,by="code",all.x=TRUE) # View(france_beds) # france_reg<-merge(france_reg,france_beds_reg,by.x="code",by.y="code_reg",all.x=TRUE) france_reg<-france_reg[order(france_reg$location,france_reg$date,-france_reg$total_deaths),] france_reg$date<-as.Date(france_reg$date) france_reg$cas_confirmes_approx<-ave(france_reg$cas_confirmes,france_reg$location,FUN=function(x) na.approx(x,na.rm=FALSE)) france_reg$death_approx<-ave(france_reg$total_deaths,france_reg$location,FUN=function(x) na.approx(x,na.rm=FALSE)) france_reg$hospitalises_approx<-ave(france_reg$hospitalises,france_reg$location,FUN=function(x) na.approx(x,na.rm=FALSE)) france_reg$gueris_approx<-ave(france_reg$gueris,france_reg$location,FUN=function(x) na.approx(x,na.rm=FALSE)) france_reg$reanimation_approx<-ave(france_reg$reanimation,france_reg$location,FUN=function(x) na.approx(x,na.rm=FALSE)) france_reg$mild_cases_approx<-france_reg$cas_confirmes_approx-france_reg$death_approx-france_reg$hospitalises_approx-france_reg$gueris_approx france_reg$lcas_confirmes_approx<-simplelag(france_reg$cas_confirmes_approx,outside=0) france_reg$lmild_cases_approx<-simplelag(france_reg$mild_cases_approx,outside=0) france_reg$llocation<-simplelag(as.character(france_reg$location),outside = "") france_reg$continuity_approx0<-ifelse(as.character(france_reg$location) != france_reg$llocation, 0, ifelse(is.na(france_reg$lmild_cases_approx)==TRUE, france_reg$lcas_confirmes_approx-france_reg$hospitalises_approx+france_reg$gueris_approx+france_reg$death_approx, france_reg$lmild_cases_approx)) france_reg$continuity_approx<-retain(france_reg$continuity_approx0, (is.na(france_reg$cas_confirmes_approx)==TRUE & is.na(france_reg$lcas_confirmes_approx)==FALSE) | as.character(france_reg$location) != france_reg$llocation ,0) france_reg$total_deaths<-france_reg$death_approx france_reg$total_cases<-ifelse(is.na(france_reg$cas_confirmes_approx) %in% FALSE,france_reg$cas_confirmes_approx, france_reg$hospitalises_approx+france_reg$gueris_approx+france_reg$death_approx+france_reg$continuity_approx) france_reg$new_deaths<-france_reg$total_deaths-simplelag(france_reg$total_deaths,france_reg$location,outside=0) france_reg$new_cases<-france_reg$total_cases-simplelag(france_reg$total_cases,france_reg$location,outside=0) france_reg$hospitalization<-france_reg$hospitalises_approx/france_reg$population france_reg$hospitalization_evol<-france_reg$hospitalization-simplelag(france_reg$hospitalization,france_reg$location,outside=0) france_reg$reanimation<-france_reg$reanimation_approx/france_reg$population france_reg$reanimation_evol<-france_reg$reanimation-simplelag(france_reg$reanimation,france_reg$location,outside=0) france_reg$cases_2_pop<-10000*france_reg$total_cases/france_reg$population france_reg$deaths_2_pop<-100000*france_reg$death_approx/france_reg$population #French departments france_dep<-france[france$granularite %in% "departement",] france_dep<-france_dep[order(france_dep$location,france_dep$date,-france_dep$total_deaths),] france_dep$sel<-ave((france_dep$location !=""),paste(france_dep$location,france_dep$date),FUN=function(x) cumsum(x)) france_dep<-france_dep[france_dep$sel %in% 1,] france_dep$code<-substr(france_dep$maille_code,5,7) france_dep<-merge(france_dep,france_dep_pop,by="code",all.x=TRUE) france_dep<-merge(france_dep,france_beds,by.x="code",by.y="code_dep",all.x=TRUE) france_dep<-france_dep[order(france_dep$location,france_dep$date,-france_dep$total_deaths),] france_dep$date<-as.Date(france_dep$date) france_dep$cas_confirmes_approx<-ave(france_dep$cas_confirmes,france_dep$location,FUN=function(x) na.approx(x,na.rm=FALSE)) france_dep$death_approx<-ave(france_dep$total_deaths,france_dep$location,FUN=function(x) na.approx(x,na.rm=FALSE)) france_dep$hospitalises_approx<-ave(france_dep$hospitalises,france_dep$location,FUN=function(x) na.approx(x,na.rm=FALSE)) france_dep$gueris_approx<-ave(france_dep$gueris,france_dep$location,FUN=function(x) na.approx(x,na.rm=FALSE)) france_dep$reanimation_approx<-ave(france_dep$reanimation,france_dep$location,FUN=function(x) na.approx(x,na.rm=FALSE)) france_dep$hospitalization<-france_dep$hospitalises_approx/france_dep$population france_dep$hospitalization_evol<-france_dep$hospitalization-simplelag(france_dep$hospitalization,france_dep$location,outside=0) france_dep$reanimation<-france_dep$reanimation_approx/france_dep$population france_dep$reanimation_evol<-france_dep$reanimation-simplelag(france_dep$reanimation,france_dep$location,outside=0) france_dep$mild_cases_approx<-france_dep$cas_confirmes_approx-france_dep$death_approx-france_dep$hospitalises_approx-france_dep$gueris_approx france_dep$lcas_confirmes_approx<-simplelag(france_dep$cas_confirmes_approx,outside=0) france_dep$lmild_cases_approx<-simplelag(france_dep$mild_cases_approx,outside=0) france_dep$llocation<-simplelag(as.character(france_dep$location),outside = "") france_dep$continuity_approx0<-ifelse(as.character(france_dep$location) != france_dep$llocation, 0, ifelse(is.na(france_dep$lmild_cases_approx)==TRUE, france_dep$lcas_confirmes_approx-france_dep$hospitalises_approx+france_dep$gueris_approx+france_dep$death_approx, france_dep$lmild_cases_approx)) france_dep$continuity_approx<-retain(france_dep$continuity_approx0, (is.na(france_dep$cas_confirmes_approx)==TRUE & is.na(france_dep$lcas_confirmes_approx)==FALSE) | as.character(france_dep$location) != france_dep$llocation ,0) france_dep$total_cases<-ifelse(is.na(france_dep$cas_confirmes_approx) %in% FALSE,france_dep$cas_confirmes_approx, france_dep$hospitalises_approx+france_dep$gueris_approx+france_dep$death_approx+france_dep$continuity_approx) france_dep$total_deaths<-france_dep$death_approx france_dep$new_deaths<-france_dep$total_deaths-simplelag(france_dep$total_deaths,france_dep$location,outside=0) france_dep$new_cases<-france_dep$total_cases-simplelag(france_dep$total_cases,france_dep$location,outside=0) france_dep$cases_2_pop<-10000*france_dep$total_cases/france_dep$population france_dep$deaths_2_pop<-100000*france_dep$death_approx/france_dep$population france_dep$nb_beds<-france_dep$beds2012*france_dep$population/100000 france_dep$hospitalized_per_beds<-france_dep$hospitalises_approx/france_dep$nb_beds france_dep$reanimation_per_beds<-france_dep$reanimation_approx/france_dep$nb_beds #UK #UK country Cases and deaths uk_countries2<-merge(uk_countries[uk_countries$Indicator %in% "ConfirmedCases",c("Date","Country","Value")], uk_countries[uk_countries$Indicator %in% "Deaths",c("Date","Country","Value")], by=c("Country","Date"),all=TRUE) colnames(uk_countries2)<-c("Country","Date","total_cases","total_deaths") uk_countries2<-merge(uk_countries2, uk_countries[uk_countries$Indicator %in% "Tests",c("Date","Country","Value")], by=c("Country","Date"),all=TRUE) colnames(uk_countries2)<-c("Country","date","total_cases","total_deaths","total_tests") uk_countries2$date<-as.Date(uk_countries2$date) #England Cases england_cases2<-uk_cases[uk_cases$Area.type=="Region",] colnames(england_cases2)<-c("region","code","type","date","new_cases","Previously.reported.daily.cases","Change.in.daily.cases","total_cases") england_cases2$region<-as.character(england_cases2$region) england_cases2$region[england_cases2$region=="North East"]<-"North East and Yorkshire" england_cases2$region[england_cases2$region=="Yorkshire and The Humber"]<-"North East and Yorkshire" england_cases2$region[england_cases2$region=="West Midlands"]<-"Midlands" england_cases2$region[england_cases2$region=="East Midlands"]<-"Midlands" england_cases3<-as.data.frame.table(tapply(england_cases2$new_cases,list(england_cases2$region,england_cases2$date),sum,na.rm=TRUE)) colnames(england_cases3)<-c("region","date","new_cases") england_cases4<-as.data.frame.table(tapply(england_cases2$total_cases,list(england_cases2$region,england_cases2$date),sum,na.rm=TRUE)) colnames(england_cases4)<-c("region","date","total_cases") england_cases5<-merge(england_cases3,england_cases4,by=c("region","date"),all=TRUE) england_cases5$date<-as.Date(as.character(england_cases5$date)) #England deaths england_deaths<-as.data.frame(england_deaths[(3:nrow(england_deaths)),c(1,3:(ndays+2))]) colnames(england_deaths)<-c("region",paste("d",c((as.numeric(ukdate)-ndays+1):as.numeric(ukdate)),sep="_")) england_deaths2<-reshape(england_deaths, varying = list(2:(ndays+1)), times=gsub("d_","",colnames(england_deaths)[2:(ndays+1)]), v.names = "new_deaths",direction = "long") england_deaths2$date<-as.Date(as.numeric(england_deaths2$time)) rownames(england_deaths2)<-NULL england_deaths2$region[england_deaths2$region=="North East And Yorkshire"]<-"North East and Yorkshire" england_deaths2$region[england_deaths2$region=="East Of England"]<-"East of England" england_deaths2$new_deaths<-as.numeric(england_deaths2$new_deaths) # View(england_deaths2) england<-merge(england_cases5[,c("region","date","new_cases","total_cases")],england_deaths2[,c("region","date","new_deaths")],by=c("region","date"),all=TRUE) # england_deaths_old<-as.data.frame(england_deaths_old[(3:nrow(england_deaths_old)),c(1,3:(ndays_old+2))]) # colnames(england_deaths_old)<-c("region",paste("d",c((as.numeric(uk_end_old)-ndays_old+1):as.numeric(uk_end_old)),sep="_")) # england_deaths_old2<-reshape(england_deaths_old, # varying = list(2:(ndays+1)), # times=gsub("d_","",colnames(england_deaths_old)[2:(ndays+1)]), # v.names = "new_deaths_old",direction = "long") # england_deaths_old2$date<-as.Date(as.numeric(england_deaths_old2$time)) # rownames(england_deaths_old2)<-NULL # england_deaths_old2$region[england_deaths_old2$region=="North East And Yorkshire"]<-"North East and Yorkshire" # england_deaths_old2$region[england_deaths_old2$region=="East Of England"]<-"East of England" # # england_b<-merge(england[,c("region","date","new_cases","total_cases","new_deaths")],england_deaths_old2[,c("region","date","new_deaths_old")],by=c("region","date"),all=TRUE) #Uk global file uk<-rbind.fill(uk_countries2,england) uk$location<-ifelse(is.na(uk$region),as.character(uk$Country),as.character(uk$region)) uk<-uk[(uk$location %in% c("England","UK",NA)) %in% FALSE,] uk<-uk[order(uk$location,uk$date),] uk$date<-as.Date(uk$date) uk$new_cases2<-uk$total_cases-simplelag(uk$total_cases,uk$location,outside=0) uk$new_cases<-ifelse(is.na(uk$new_cases),uk$new_cases2,uk$new_cases) uk$new_deaths2<-uk$total_deaths-simplelag(uk$total_deaths,uk$location,outside=0) uk$new_deaths<-ifelse(is.na(uk$new_deaths),uk$new_deaths2,uk$new_deaths) uk$total_deaths2<-ave(ifelse(is.na(uk$new_deaths),0,uk$new_deaths),uk$location,FUN=function(x) cumsum(x)) uk$total_deaths<-ifelse(is.na(uk$total_deaths),uk$total_deaths2,as.numeric(uk$total_deaths)) uk<-uk[,c("location","date","total_cases","new_cases","total_deaths","new_deaths")] #Pop England pop_england<-pop_england[,c(1,2,4)] colnames(pop_england)<-c("location","population","area") pop_england$population<-as.numeric(gsub(",","",pop_england$population)) pop_england$area<-as.numeric(gsub(",","",substr(pop_england$area,1,regexpr("km",pop_england$area)-3))) pop_england2<-pop_england[pop_england$location=="Yorkshire and the Humber",c(2:3)]+pop_england[pop_england$location=="North East",c(2:3)] pop_england2$location<-"North East and Yorkshire" pop_england3<-pop_england[pop_england$location=="East Midlands",c(2:3)]+pop_england[pop_england$location=="West Midlands",c(2:3)] pop_england3$location<-"Midlands" pop_uk_country<-pop_uk_country[c(2:4),c(2,3,5)] colnames(pop_uk_country)<-c("location","population","area") pop_uk_country$location<-iconv(pop_uk_country$location,"UTF-8","latin1") pop_uk_country$population<-as.numeric(gsub(",","",pop_uk_country$population)) pop_uk_country$area<-as.numeric(gsub(",","",substr(pop_uk_country$area,1,regexpr("km",pop_uk_country$area)-3))) pop_uk<-rbind.fill(pop_england,pop_england2,pop_england3,pop_uk_country) uk<-merge(uk,pop_uk,by="location",all.x = TRUE) uk<-uk[order(uk$location,uk$date),] uk$cases_2_pop<-10000*uk$total_cases/uk$population uk$deaths_2_pop<-100000*uk$total_deaths/uk$population uk$date<-as.Date(uk$date) uk<-uk[uk$date != max(uk$date),] #Germany germany$date<-as.Date(substr(germany$Meldedatum,1,10)) germany$location<-germany$Bundesland germany$location_id<-as.numeric(germany$IdBundesland) germany$location_det<-germany$Landkreis germany$location_det_id<-as.numeric(germany$IdLandkreis) germany$new_cases<-germany$AnzahlFall germany$new_deaths<-germany$AnzahlTodesfall germany$date<-as.Date(germany$date) #German lander germany_land1<-as.data.frame.table(tapply(germany$new_cases,list(germany$location,germany$date),sum,na.rm=TRUE)) germany_land2<-as.data.frame.table(tapply(germany$new_deaths,list(germany$location,germany$date),sum,na.rm=TRUE)) colnames(germany_land1)<-c("location","date","new_cases") colnames(germany_land2)<-c("location","date","new_deaths") germany_land<-merge(germany_land1,germany_land2,by=c("location","date"),all=TRUE) germany_land_id<-unique(germany[,c("location","location_id")]) germany_land<-merge(germany_land,germany_land_id,by=c("location"),all=TRUE) germany_land<-merge(germany_land,pop_germany[,c("region_id","population","density")],by.x="location_id",by.y="region_id",all.x=TRUE) germany_land$date<-as.Date(germany_land$date) germany_land<-germany_land[order(germany_land$location,germany_land$date),] # pop_germany$location<-iconv(pop_germany$Land,"UTF-8","latin1") # pop_germany$population<-as.numeric(gsub(",","",pop_germany$Einwohner))*1000 # pop_germany$density<-as.numeric(pop_germany$Einwohner_km2) germany_land$new_cases<-ifelse(is.na(germany_land$new_cases),0,germany_land$new_cases) germany_land$new_deaths<-ifelse(is.na(germany_land$new_deaths),0,germany_land$new_deaths) germany_land$total_cases<-ave(germany_land$new_cases,germany_land$location,FUN=function(x) cumsum(x)) germany_land$total_deaths<-ave(germany_land$new_deaths,germany_land$location,FUN=function(x) cumsum(x)) germany_land$cases_2_pop<-10000*germany_land$total_cases/germany_land$population germany_land$deaths_2_pop<-100000*germany_land$total_deaths/germany_land$population germany_land<-germany_land[order(germany_land$location,germany_land$date),] germany_land<-germany_land[germany_land$date != max(germany_land$date),] #German region str(germany) germany_reg1<-as.data.frame.table(tapply(germany$new_cases,list(germany$location_det,germany$date),sum,na.rm=TRUE)) germany_reg2<-as.data.frame.table(tapply(germany$new_deaths,list(germany$location_det,germany$date),sum,na.rm=TRUE)) colnames(germany_reg1)<-c("location","date","new_cases") colnames(germany_reg2)<-c("location","date","new_deaths") germany_reg<-merge(germany_reg1,germany_reg2,by=c("location","date"),all=TRUE) germany_reg_id<-unique(germany[,c("location_det","location_det_id")]) germany_reg<-merge(germany_reg,germany_reg_id,by.x=c("location"),by.y=c("location_det"),all=TRUE) germany_reg<-merge(germany_reg,pop_germany[,c("region_id","population","density")],by.x="location_det_id",by.y="region_id",all.x=TRUE) germany_reg<-germany_reg[order(germany_reg$location,germany_reg$date),] germany_reg$date<-as.Date(germany_reg$date) germany_reg$new_cases<-ifelse(is.na(germany_reg$new_cases),0,germany_reg$new_cases) germany_reg$new_deaths<-ifelse(is.na(germany_reg$new_deaths),0,germany_reg$new_deaths) germany_reg$total_cases<-ave(germany_reg$new_cases,germany_reg$location,FUN=function(x) cumsum(x)) germany_reg$total_deaths<-ave(germany_reg$new_deaths,germany_reg$location,FUN=function(x) cumsum(x)) germany_reg$cases_2_pop<-10000*germany_reg$total_cases/germany_reg$population germany_reg$deaths_2_pop<-100000*germany_reg$total_deaths/germany_reg$population germany_reg<-germany_reg[germany_reg$date != max(germany_reg$date),] #USA usa$date<-as.Date(usa$date) usa$location<-usa$state usa$total_cases<-usa$cases usa$total_deaths<-usa$deaths usa<-usa[order(usa$location,usa$date),] usa$new_deaths<-usa$total_deaths-simplelag(usa$total_deaths,usa$location,outside=0) usa$new_cases<-usa$total_cases-simplelag(usa$total_cases,usa$location,outside=0) usa<-merge(usa,usa_pop[,c("state","population")],by="state",all.x=TRUE) usa$cases_2_pop<-10000*usa$total_cases/usa$population usa$deaths_2_pop<-100000*usa$total_deaths/usa$population usa<-usa[order(usa$location,usa$date),] str(usa) #China china<-world_region[world_region$Country.Region=="China",] china$location<-factor(china$location) china_pop$population<-as.numeric(gsub(",","",china_pop$Population)) china_pop$location<-china_pop$Administrative_Division china<-merge(china,china_pop[,c("population","location")],by="location",all.x=TRUE) china$cases_2_pop<-10000*china$total_cases/china$population china$deaths_2_pop<-100000*china$total_deaths/china$population china<-china[order(china$location,china$date),] #canada canada<-world_region[world_region$Country.Region=="Canada",] canada$location<-factor(canada$location) canada_pop$population<-as.numeric(gsub(",","",canada_pop$Population_2020)) deb<-regexpr("Ontario",canada_pop$Name[1])[1] canada_pop$location<-substr(canada_pop$Name,deb,nchar(canada_pop$Name)) canada<-merge(canada,canada_pop[,c("population","location")],by="location",all.x=TRUE) canada$cases_2_pop<-10000*canada$total_cases/canada$population canada$deaths_2_pop<-100000*canada$total_deaths/canada$population canada<-canada[order(canada$location,canada$date),] #australia australia<-world_region[world_region$Country.Region=="Australia",] australia$location<-factor(australia$location) australia_pop$population<-as.numeric(gsub(",","",australia_pop$Population)) australia_pop$location<-australia_pop$State_name australia<-merge(australia,australia_pop[,c("population","location")],by="location",all.x=TRUE) australia$cases_2_pop<-10000*australia$total_cases/australia$population australia$deaths_2_pop<-100000*australia$total_deaths/australia$population australia<-australia[order(australia$location,australia$date),] world_cluster<-rbind.fill(china[china$location %in% "Hubei" & china$date",death_2_pop_threshold) label_cases_2_pop<-paste("Days since number of cases for 10,000 inhabitants >",cases_2_pop_threshold) my_last_date<-substr(as.vector(as.data.frame(table(gdata$date))[length(table(gdata$date)),"Var1"]),1,10) gdata$new_cases_7<-rowMeans(data.frame(gdata$new_cases, simplelag(gdata$new_cases,gdata$location,mylag = 1,outside =0), simplelag(gdata$new_cases,gdata$location,mylag = 2,outside =0), simplelag(gdata$new_cases,gdata$location,mylag = 3,outside =0), simplelag(gdata$new_cases,gdata$location,mylag = 4,outside =0), simplelag(gdata$new_cases,gdata$location,mylag = 5,outside =0), simplelag(gdata$new_cases,gdata$location,mylag = 6,outside =0)),na.rm=TRUE) gdata$new_deaths_7<-rowMeans(cbind(gdata$new_deaths, simplelag(gdata$new_deaths,gdata$location,mylag = 1,outside =0), simplelag(gdata$new_deaths,gdata$location,mylag = 2,outside =0), simplelag(gdata$new_deaths,gdata$location,mylag = 3,outside =0), simplelag(gdata$new_deaths,gdata$location,mylag = 4,outside =0), simplelag(gdata$new_deaths,gdata$location,mylag = 5,outside =0), simplelag(gdata$new_deaths,gdata$location,mylag = 6,outside =0)),na.rm = TRUE) ##TOTAL CASES 2 POP SINCE TOTAL CASES ABOVE THRESHOLD gdata$dtot_n<-ave((ifelse(is.na(gdata$cases_2_pop),0,gdata$cases_2_pop)>cases_2_pop_threshold & gdata$population>population_threshold),gdata$location,FUN=function(x) cumsum(x)) gdata_n<-gdata[(gdata$dtot_n>0) %in% TRUE,] gdata_n$location<-factor(gdata_n$location) gdata_n_i6<-tapply(gdata_n$cases_2_pop,list(gdata_n$dtot_n,gdata_n$location), mean, na.rm=TRUE) vmax<-data.frame(apply(as.data.frame(gdata_n_i6),2,function(x) max(x,na.rm=TRUE))) colnames(vmax)<-"max" vmax$rank<-rank(-vmax$max) vmax$location<-row.names(vmax) vmax$row<-cumsum(1-is.na(row.names(vmax))) gdata_n_i6<-gdata_n_i6[,vmax$row[vmax$rank<=25]] matplot(gdata_n_i6,pch=my_pch,col=my_col,ylab="Cases for 10,000 inhabitants (log scale)", xlim = c(0,nrow(gdata_n_i6)+10), log="y", las = 1,cex.axis=0.8,xlab=label_cases_2_pop) matlines(gdata_n_i6,col=my_col) title(main=paste(country,"-",unit,": 1. Cases for 10,000 inhabitants on",my_last_date)) legend("bottomright",bg="transparent",legend=colnames(gdata_n_i6),col=my_col, text.col = my_col,box.lwd=-1, lty=1, pch=my_pch,ncol=1,cex=0.8) #NEW CASES 2 POP SINCE TOTAL CASES ABOVE THRESHOLD gdata$new_cases_2_pop<-10000*gdata$new_cases_7/gdata$population gdata$dtot_n<-ave((ifelse(is.na(gdata$cases_2_pop),0,gdata$cases_2_pop)>cases_2_pop_threshold & gdata$population>population_threshold),gdata$location,FUN=function(x) cumsum(x)) gdata_n<-gdata[(gdata$dtot_n>0) %in% TRUE,] gdata_n$location<-factor(gdata_n$location) gdata_n_i6<-tapply(gdata_n$new_cases_2_pop,list(gdata_n$dtot_n,gdata_n$location), mean, na.rm=TRUE) gdata_n_i6<-gdata_n_i6[,vmax$row[vmax$rank<=25]] matplot(gdata_n_i6,pch=my_pch,col=my_col,ylab="New cases for 10,000 inhabitants (7-day moving average - log scale)", log="y", las = 1,cex.axis=0.8,xlab=label_cases_2_pop,xlim = c(0,nrow(gdata_n_i6)+10)) matlines(gdata_n_i6,col=my_col) title(main=paste(country,"-",unit,": 2. New cases for 10,000 inhabitants on",my_last_date)) legend("bottomright",bg="transparent",legend=colnames(gdata_n_i6),col=my_col, text.col = my_col,box.lwd=-1, lty=1, pch=my_pch,ncol=1,cex=0.8) #TOTAL DEATHS 2 POP SINCE TOTAL DEATHS ABOVE THRESHOLD gdata$dtot_n<-ave((ifelse(is.na(gdata$deaths_2_pop),0,gdata$deaths_2_pop)>death_2_pop_threshold & gdata$population>population_threshold),gdata$location,FUN=function(x) cumsum(x)) gdata_n<-gdata[(gdata$dtot_n>0) %in% TRUE,] gdata_n$location<-factor(gdata_n$location) gdata_n_i6<-tapply(gdata_n$deaths_2_pop,list(gdata_n$dtot_n,gdata_n$location), mean, na.rm=TRUE) vmax<-data.frame(apply(as.data.frame(gdata_n_i6),2,function(x) max(x,na.rm=TRUE))) colnames(vmax)<-"max" vmax$rank<-rank(-vmax$max) vmax$location<-row.names(vmax) vmax$row<-cumsum(1-is.na(row.names(vmax))) dmax<-vmax gdata_n_i6<-gdata_n_i6[,vmax$row[vmax$rank<=25]] matplot(gdata_n_i6,pch=my_pch,col=my_col,ylab="Deaths for 100,000 inhabitants (log scale)", log="y", las = 1,cex.axis=0.8,xlab=label_death_2_pop,xlim = c(0,nrow(gdata_n_i6)+10)) matlines(gdata_n_i6,col=my_col) title(main=paste(country,"-",unit,": 3. Deaths for 100,000 inhabitants on",my_last_date)) legend("bottomright",bg="transparent",legend=colnames(gdata_n_i6),col=my_col, text.col = my_col,box.lwd=-1, lty=1, pch=my_pch,ncol=1,cex=0.8) #New DEATHS 2 POP SINCE TOTAL DEATHS ABOVE THRESHOLD gdata$new_deaths_2_pop<-100000*gdata$new_deaths_7/gdata$population gdata$dtot_n<-ave((ifelse(is.na(gdata$deaths_2_pop),0,gdata$deaths_2_pop)>death_2_pop_threshold & gdata$population>population_threshold),gdata$location,FUN=function(x) cumsum(x)) gdata_n<-gdata[(gdata$dtot_n>0) %in% TRUE,] gdata_n$location<-factor(gdata_n$location) gdata_n_i6<-tapply(gdata_n$new_deaths_2_pop,list(gdata_n$dtot_n,gdata_n$location), mean, na.rm=TRUE) gdata_n_i6<-gdata_n_i6[,vmax$row[vmax$rank<=25]] matplot(gdata_n_i6,pch=my_pch,col=my_col,ylab="New deaths for 100,000 inhabitants (7-day moving average - log scale)", log="y", las = 1,cex.axis=0.8,xlab=label_death_2_pop,xlim = c(0,nrow(gdata_n_i6)+10)) matlines(gdata_n_i6,col=my_col) title(main=paste(country,"-",unit,": 4. New deaths for 100,000 inhabitants on",my_last_date)) legend("bottomright",bg="transparent",legend=colnames(gdata_n_i6),col=my_col, text.col = my_col,box.lwd=-1, lty=1, pch=my_pch,ncol=1,cex=0.8) #LETALITY DEATHS 2 CASES SINCE TOTAL DEATHS ABOVE THRESHOLD gdata$deaths_2_cases<-100*gdata$total_deaths/gdata$total_cases gdata$dtot_n<-ave((ifelse(is.na(gdata$deaths_2_pop),0,gdata$deaths_2_pop)>death_2_pop_threshold & gdata$population>population_threshold),gdata$location,FUN=function(x) cumsum(x)) gdata_n<-gdata[(gdata$dtot_n>0) %in% TRUE,] gdata_n$location<-factor(gdata_n$location) gdata_n_i6<-tapply(gdata_n$deaths_2_cases,list(gdata_n$dtot_n,gdata_n$location), mean, na.rm=TRUE) gdata_n_i6<-gdata_n_i6[,vmax$row[vmax$rank<=25]] matplot(gdata_n_i6,pch=my_pch,col=my_col,ylab="Deaths for 100 cases (log scale)", log="y", las = 1,cex.axis=0.8,xlab=label_death_2_pop,xlim = c(0,nrow(gdata_n_i6)+10)) matlines(gdata_n_i6,col=my_col) title(main=paste(country,"-",unit,": 5. Deaths for 100 cases on",my_last_date)) legend("bottomright",bg="transparent",legend=colnames(gdata_n_i6),col=my_col, text.col = my_col,box.lwd=-1, lty=1, pch=my_pch,ncol=1,cex=0.8) #ACTIVE CASES FOR HOSPITAL BEDS gdata$dtot_n<-ave((ifelse(is.na(gdata$deaths_2_pop),0,gdata$deaths_2_pop)>death_2_pop_threshold & gdata$population>population_threshold),gdata$location,FUN=function(x) cumsum(x)) gdata_n<-gdata[(gdata$dtot_n>0) %in% TRUE,] gdata_n$location<-factor(gdata_n$location) gdata_n_i6<-tapply(100*gdata_n$active_cases_per_beds,list(gdata_n$dtot_n,gdata_n$location), mean, na.rm=TRUE) gdata_n_i6<-gdata_n_i6[,vmax$row[vmax$rank<=25]] matplot(gdata_n_i6,pch=my_pch,col=my_col,ylab="Active cases for 100 hospital beds (log scale)", log="y", las = 1,cex.axis=0.8,xlab=label_death_2_pop,xlim = c(0,nrow(gdata_n_i6)+10)) matlines(gdata_n_i6,col=my_col) title(main=paste(country,"-",unit,": 6. Active cases for 100 hospital beds on",my_last_date)) legend("bottomright",bg="transparent",legend=colnames(gdata_n_i6),col=my_col, text.col = my_col,box.lwd=-1, lty=1, pch=my_pch,ncol=1,cex=0.8) #New DEATHS 2 POP SINCE TOTAL DEATHS ABOVE THRESHOLD 6 BIGGEST 10 DAY INCREASE gdata$new_deaths_2_pop<-100000*gdata$new_deaths_7/gdata$population gdata$dtot_n<-ave((gdata$population>population_threshold),gdata$location,FUN=function(x) cumsum(x)) gdata_n<-gdata[(gdata$dtot_n>0) %in% TRUE,] gdata_n$location<-factor(gdata_n$location) gdata_n_i5<-tapply(gdata_n$new_deaths_2_pop,list(gdata_n$date,gdata_n$location), mean, na.rm=TRUE) vmax<-data.frame(gdata_n_i5[nrow(gdata_n_i5),]-gdata_n_i5[nrow(gdata_n_i5)-7,]) colnames(vmax)<-"max" vmax$rank<-rank(-vmax$max) vmax$rank2<-rank(vmax$max) vmax$location<-row.names(vmax) vmax$row<-cumsum(1-is.na(row.names(vmax))) gdata_n_i6<-as.data.frame.matrix(gdata_n_i5[,vmax$row[vmax$rank<=10]]) rowMeans(gdata_n_i6,na.rm=TRUE) # gdata_n_i6<-gdata_n_i6[is.na(rowMeans(gdata_n_i6,na.rm=TRUE)) %in% FALSE # & rowMeans(gdata_n_i6,na.rm=TRUE)>0 # ,] gdata_n_i6<-gdata_n_i6[as.Date(rownames(gdata_n_i6))>as.Date("2020-02-20"),] date<-as.Date(rownames(gdata_n_i6)) matplot(date,gdata_n_i6, pch=my_pch,col=my_col,ylab="New deaths per day for 100,000 inhabitants (7-day moving average)", #log="y", las = 1,cex.axis=0.8,xaxt="n") axis.Date(1,date,format="%m-%d",las=1) matlines(date,gdata_n_i6,col=my_col) title(main=paste(country,"- Top 10 countries where new deaths for 100,000 inhabitants increased the most last week"),cex.main=1) legend("topleft",bg="transparent",legend=colnames(gdata_n_i6[]),col=my_col, text.col = my_col,box.lwd=-1, lty=1, pch=my_pch,ncol=1,cex=0.8) gdata_n_i6<-as.data.frame.matrix(gdata_n_i5[,vmax$row[vmax$rank2<=10]]) rowMeans(gdata_n_i6,na.rm=TRUE) # gdata_n_i6<-gdata_n_i6[is.na(rowMeans(gdata_n_i6,na.rm=TRUE)) %in% FALSE # & rowMeans(gdata_n_i6,na.rm=TRUE)>0 # ,] gdata_n_i6<-gdata_n_i6[as.Date(rownames(gdata_n_i6))>as.Date("2020-02-20"),] date<-as.Date(rownames(gdata_n_i6)) matplot(date,gdata_n_i6, pch=my_pch,col=my_col,ylab="New deaths per day for 100,000 inhabitants (7-day moving average)", #log="y", las = 1,cex.axis=0.8,xaxt="n") axis.Date(1,date,format="%m-%d",las=1) matlines(date,gdata_n_i6,col=my_col) #grid( lwd = 2) title(main=paste(country,"-Top 10 countries where new deaths for 100,000 inhabitants decreased the most last week"),cex.main=1) legend("topleft",bg="transparent",legend=colnames(gdata_n_i6[]),col=my_col, text.col = my_col,box.lwd=-1, lty=1, pch=my_pch,ncol=1,cex=0.8) #New cases 2 POP SINCE TOTAL cases ABOVE THRESHOLD 6 BIGGEST 10 DAY INCREASE gdata$new_cases_2_pop<-100000*gdata$new_cases_7/gdata$population gdata$dtot_n<-ave((gdata$population>population_threshold),gdata$location,FUN=function(x) cumsum(x)) gdata_n<-gdata[(gdata$dtot_n>0) %in% TRUE,] gdata_n$location<-factor(gdata_n$location) gdata_n_i5<-tapply(gdata_n$new_cases_2_pop,list(gdata_n$date,gdata_n$location), mean, na.rm=TRUE) vmax<-data.frame(gdata_n_i5[nrow(gdata_n_i5),]-gdata_n_i5[nrow(gdata_n_i5)-7,]) colnames(vmax)<-"max" vmax$rank<-rank(-vmax$max) vmax$rank2<-rank(vmax$max) vmax$location<-row.names(vmax) vmax$row<-cumsum(1-is.na(row.names(vmax))) gdata_n_i6<-as.data.frame.matrix(gdata_n_i5[,vmax$row[vmax$rank<=10]]) rowMeans(gdata_n_i6,na.rm=TRUE) # gdata_n_i6<-gdata_n_i6[is.na(rowMeans(gdata_n_i6,na.rm=TRUE)) %in% FALSE # & rowMeans(gdata_n_i6,na.rm=TRUE)>0 # ,] gdata_n_i6<-gdata_n_i6[as.Date(rownames(gdata_n_i6))>as.Date("2020-02-15"),] date<-as.Date(rownames(gdata_n_i6)) matplot(date,gdata_n_i6, pch=my_pch,col=my_col,ylab="New cases per day for 100,000 inhabitants (7-day moving average)", # log="y", las = 1,cex.axis=0.8,xaxt="n") axis.Date(1,date,format="%m-%d",las=1) matlines(date,gdata_n_i6,col=my_col) title(main=paste(country,"- Top 10 countries where new cases for 100,000 inhabitants increased the most last week"),cex.main=1) legend("topleft",bg="transparent",legend=colnames(gdata_n_i6[]),col=my_col, text.col = my_col,box.lwd=-1, lty=1, pch=my_pch,ncol=1,cex=0.8) gdata_n_i6<-as.data.frame.matrix(gdata_n_i5[,vmax$row[vmax$rank2<=10]]) rowMeans(gdata_n_i6,na.rm=TRUE) # gdata_n_i6<-gdata_n_i6[is.na(rowMeans(gdata_n_i6,na.rm=TRUE)) %in% FALSE # & rowMeans(gdata_n_i6,na.rm=TRUE)>0 # ,] gdata_n_i6<-gdata_n_i6[as.Date(rownames(gdata_n_i6))>as.Date("2020-02-15"),] date<-as.Date(rownames(gdata_n_i6)) matplot(date,gdata_n_i6, pch=my_pch,col=my_col,ylab="New cases per day for 100,000 inhabitants (7-day moving average)", # log="y", las = 1,cex.axis=0.8,xaxt="n") axis.Date(1,date,format="%m-%d",las=1) matlines(date,gdata_n_i6,col=my_col) #grid( lwd = 2) title(main=paste(country,"- Top 10 countries where new cases for 100,000 inhabitants decreased the most last week"),cex.main=1) legend("topleft",bg="transparent",legend=colnames(gdata_n_i6[]),col=my_col, text.col = my_col,box.lwd=-1, lty=1, pch=my_pch,ncol=1,cex=0.8) ######################################################## #World cluster COVID GRAPHS ######################################################## gdata<-world_reg country<-"World regions" unit<-"25 top Areas & Hubei" case_threshold<-world_case_threshold death_threshold<-world_death_threshold population_threshold<-world_population_threshold death_2_pop_threshold<-world_death_2_pop_threshold cases_2_pop_threshold<-world_cases_2_pop_threshold label_cases<-paste("Days since number of cases >",case_threshold) label_death<-paste("Days since number of deaths >",death_threshold) label_death_2_pop<-paste("Days since number of deaths for 100,000 inhabitants >",death_2_pop_threshold) label_cases_2_pop<-paste("Days since number of cases for 10,000 inhabitants >",cases_2_pop_threshold) my_last_date<-substr(as.vector(as.data.frame(table(gdata$date))[length(table(gdata$date)),"Var1"]),1,10) gdata$new_cases_7<-rowMeans(data.frame(gdata$new_cases, simplelag(gdata$new_cases,gdata$location,mylag = 1,outside =0), simplelag(gdata$new_cases,gdata$location,mylag = 2,outside =0), simplelag(gdata$new_cases,gdata$location,mylag = 3,outside =0), simplelag(gdata$new_cases,gdata$location,mylag = 4,outside =0), simplelag(gdata$new_cases,gdata$location,mylag = 5,outside =0), simplelag(gdata$new_cases,gdata$location,mylag = 6,outside =0)),na.rm=TRUE) gdata$new_deaths_7<-rowMeans(cbind(gdata$new_deaths, simplelag(gdata$new_deaths,gdata$location,mylag = 1,outside =0), simplelag(gdata$new_deaths,gdata$location,mylag = 2,outside =0), simplelag(gdata$new_deaths,gdata$location,mylag = 3,outside =0), simplelag(gdata$new_deaths,gdata$location,mylag = 4,outside =0), simplelag(gdata$new_deaths,gdata$location,mylag = 5,outside =0), simplelag(gdata$new_deaths,gdata$location,mylag = 6,outside =0)),na.rm = TRUE) ##TOTAL CASES 2 POP SINCE TOTAL CASES ABOVE THRESHOLD gdata$dtot_n<-ave((ifelse(is.na(gdata$cases_2_pop),0,gdata$cases_2_pop)>cases_2_pop_threshold & gdata$population>population_threshold),gdata$location,FUN=function(x) cumsum(x)) gdata_n<-gdata[(gdata$dtot_n>0) %in% TRUE,] gdata_n$location<-factor(gdata_n$location) gdata_n_i6<-tapply(gdata_n$cases_2_pop,list(gdata_n$dtot_n,gdata_n$location), mean, na.rm=TRUE) vmax<-data.frame(apply(as.data.frame(gdata_n_i6),2,function(x) max(x,na.rm=TRUE))) colnames(vmax)<-"max" vmax$rank<-rank(-vmax$max) vmax$location<-row.names(vmax) vmax$row<-cumsum(1-is.na(row.names(vmax))) `CN-Hubei`<-gdata_n_i6[,c("CN-Hubei")] gdata_n_i6<-gdata_n_i6[,vmax$row[vmax$rank<=25]] gdata_n_i6<-cbind(gdata_n_i6,`CN-Hubei`) matplot(gdata_n_i6,pch=my_pch,col=my_col,ylab="Cases for 10,000 inhabitants (log scale)", xlim = c(0,nrow(gdata_n_i6)+20), log="y", las = 1,cex.axis=0.8,xlab=label_cases_2_pop) matlines(gdata_n_i6,col=my_col) title(main=paste(country,"-",unit,": 1. Cases for 10,000 inhabitants on",my_last_date)) legend("bottomright",bg="transparent",legend=colnames(gdata_n_i6),col=my_col, text.col = my_col,box.lwd=-1, lty=1, pch=my_pch,ncol=1,cex=0.8) #NEW CASES 2 POP SINCE TOTAL CASES ABOVE THRESHOLD gdata$new_cases_2_pop<-10000*gdata$new_cases_7/gdata$population gdata$dtot_n<-ave((ifelse(is.na(gdata$cases_2_pop),0,gdata$cases_2_pop)>cases_2_pop_threshold & gdata$population>population_threshold),gdata$location,FUN=function(x) cumsum(x)) gdata_n<-gdata[(gdata$dtot_n>0) %in% TRUE,] gdata_n$location<-factor(gdata_n$location) gdata_n_i6<-tapply(gdata_n$new_cases_2_pop,list(gdata_n$dtot_n,gdata_n$location), mean, na.rm=TRUE) `CN-Hubei`<-gdata_n_i6[,c("CN-Hubei")] gdata_n_i6<-gdata_n_i6[,vmax$row[vmax$rank<=25]] mymin<-max(min(gdata_n_i6,na.rm = TRUE),0.1) mymax<-max(gdata_n_i6,na.rm = TRUE) gdata_n_i6<-cbind(gdata_n_i6,`CN-Hubei`) matplot(gdata_n_i6,pch=my_pch,col=my_col,ylab="New cases for 10,000 inhabitants (7-day moving average - log scale)", log="y", las = 1,cex.axis=0.8,xlab=label_cases_2_pop,xlim = c(0,nrow(gdata_n_i6)+20),ylim=c(mymin,mymax) ) matlines(gdata_n_i6,col=my_col) title(main=paste(country,"-",unit,": 2. New cases for 10,000 inhabitants on",my_last_date)) legend("bottomright",bg="transparent",legend=colnames(gdata_n_i6),col=my_col, text.col = my_col,box.lwd=-1, lty=1, pch=my_pch,ncol=1,cex=0.8) #TOTAL DEATHS 2 POP SINCE TOTAL DEATHS ABOVE THRESHOLD gdata$dtot_n<-ave((ifelse(is.na(gdata$deaths_2_pop),0,gdata$deaths_2_pop)>death_2_pop_threshold & gdata$population>population_threshold),gdata$location,FUN=function(x) cumsum(x)) gdata_n<-gdata[(gdata$dtot_n>0) %in% TRUE,] gdata_n$location<-factor(gdata_n$location) gdata_n_i6<-tapply(gdata_n$deaths_2_pop,list(gdata_n$dtot_n,gdata_n$location), mean, na.rm=TRUE) vmax<-data.frame(apply(as.data.frame(gdata_n_i6),2,function(x) max(x,na.rm=TRUE))) colnames(vmax)<-"max" vmax$rank<-rank(-vmax$max) vmax$location<-row.names(vmax) vmax$row<-cumsum(1-is.na(row.names(vmax))) dmax<-vmax `CN-Hubei`<-gdata_n_i6[,c("CN-Hubei")] gdata_n_i6<-gdata_n_i6[,vmax$row[vmax$rank<=25]] gdata_n_i6<-cbind(gdata_n_i6,`CN-Hubei`) matplot(gdata_n_i6,pch=my_pch,col=my_col,ylab="Deaths for 100,000 inhabitants (log scale)", log="y", las = 1,cex.axis=0.8,xlab=label_death_2_pop,xlim = c(0,nrow(gdata_n_i6)+20)) matlines(gdata_n_i6,col=my_col) title(main=paste(country,"-",unit,": 3. Deaths for 100,000 inhabitants on",my_last_date)) legend("bottomright",bg="transparent",legend=colnames(gdata_n_i6),col=my_col, text.col = my_col,box.lwd=-1, lty=1, pch=my_pch,ncol=1,cex=0.8) #New DEATHS 2 POP SINCE TOTAL DEATHS ABOVE THRESHOLD gdata$new_deaths_2_pop<-100000*gdata$new_deaths_7/gdata$population gdata$dtot_n<-ave((ifelse(is.na(gdata$deaths_2_pop),0,gdata$deaths_2_pop)>death_2_pop_threshold & gdata$population>population_threshold),gdata$location,FUN=function(x) cumsum(x)) gdata_n<-gdata[(gdata$dtot_n>0) %in% TRUE,] gdata_n$location<-factor(gdata_n$location) gdata_n_i6<-tapply(gdata_n$new_deaths_2_pop,list(gdata_n$dtot_n,gdata_n$location), mean, na.rm=TRUE) `CN-Hubei`<-gdata_n_i6[,c("CN-Hubei")] gdata_n_i6<-gdata_n_i6[,vmax$row[vmax$rank<=25]] mymin<-min(gdata_n_i6,na.rm = TRUE) mymax<-max(gdata_n_i6,na.rm = TRUE) gdata_n_i6<-cbind(gdata_n_i6,`CN-Hubei`) matplot(gdata_n_i6,pch=my_pch,col=my_col,ylab="New deaths for 100,000 inhabitants (7-day moving average - log scale)", log="y", las = 1,cex.axis=0.8,xlab=label_death_2_pop,xlim = c(0,nrow(gdata_n_i6)+20),ylim=c(mymin,mymax)) matlines(gdata_n_i6,col=my_col) title(main=paste(country,"-",unit,": 4. New deaths for 100,000 inhabitants on",my_last_date)) legend("bottomright",bg="transparent",legend=colnames(gdata_n_i6),col=my_col, text.col = my_col,box.lwd=-1, lty=1, pch=my_pch,ncol=1,cex=0.8) #LETALITY DEATHS 2 CASES SINCE TOTAL DEATHS ABOVE THRESHOLD gdata$deaths_2_cases<-100*gdata$total_deaths/gdata$total_cases gdata$dtot_n<-ave((ifelse(is.na(gdata$deaths_2_pop),0,gdata$deaths_2_pop)>death_2_pop_threshold & gdata$population>population_threshold),gdata$location,FUN=function(x) cumsum(x)) gdata_n<-gdata[(gdata$dtot_n>0) %in% TRUE,] gdata_n$location<-factor(gdata_n$location) gdata_n_i6<-tapply(gdata_n$deaths_2_cases,list(gdata_n$dtot_n,gdata_n$location), mean, na.rm=TRUE) `CN-Hubei`<-gdata_n_i6[,c("CN-Hubei")] gdata_n_i6<-gdata_n_i6[,vmax$row[vmax$rank<=25]] gdata_n_i6<-cbind(gdata_n_i6,`CN-Hubei`) matplot(gdata_n_i6,pch=my_pch,col=my_col,ylab="Deaths for 100 cases (log scale)", log="y", las = 1,cex.axis=0.8,xlab=label_death_2_pop,xlim = c(0,nrow(gdata_n_i6)+20)) matlines(gdata_n_i6,col=my_col) title(main=paste(country,"-",unit,": 5. Deaths for 100 cases on",my_last_date)) legend("bottomright",bg="transparent",legend=colnames(gdata_n_i6),col=my_col, text.col = my_col,box.lwd=-1, lty=1, pch=my_pch,ncol=1,cex=0.8) ######################################################## #Italy COVID GRAPHS ######################################################## gdata<-italy country<-"Italy" unit<-"Regions" case_threshold<-italy_case_threshold death_threshold<-italy_death_threshold population_threshold<-italy_population_threshold death_2_pop_threshold<-italy_death_2_pop_threshold cases_2_pop_threshold<-italy_cases_2_pop_threshold label_cases<-paste("Days since number of cases >",case_threshold) label_death<-paste("Days since number of deaths >",death_threshold) label_death_2_pop<-paste("Days since number of deaths for 100,000 inhabitants >",death_2_pop_threshold) label_cases_2_pop<-paste("Days since number of cases for 10,000 inhabitants >",cases_2_pop_threshold) my_last_date<-substr(as.vector(as.data.frame(table(gdata$date))[length(table(gdata$date)),"Var1"]),1,10) gdata$new_cases_7<-rowMeans(data.frame(gdata$new_cases, simplelag(gdata$new_cases,gdata$location,mylag = 1,outside =0), simplelag(gdata$new_cases,gdata$location,mylag = 2,outside =0), simplelag(gdata$new_cases,gdata$location,mylag = 3,outside =0), simplelag(gdata$new_cases,gdata$location,mylag = 4,outside =0), simplelag(gdata$new_cases,gdata$location,mylag = 5,outside =0), simplelag(gdata$new_cases,gdata$location,mylag = 6,outside =0)),na.rm=TRUE) gdata$new_deaths_7<-rowMeans(cbind(gdata$new_deaths, simplelag(gdata$new_deaths,gdata$location,mylag = 1,outside =0), simplelag(gdata$new_deaths,gdata$location,mylag = 2,outside =0), simplelag(gdata$new_deaths,gdata$location,mylag = 3,outside =0), simplelag(gdata$new_deaths,gdata$location,mylag = 4,outside =0), simplelag(gdata$new_deaths,gdata$location,mylag = 5,outside =0), simplelag(gdata$new_deaths,gdata$location,mylag = 6,outside =0)),na.rm = TRUE) ##TOTAL CASES 2 POP SINCE TOTAL CASES ABOVE THRESHOLD gdata$dtot_n<-ave((ifelse(is.na(gdata$cases_2_pop),0,gdata$cases_2_pop)>cases_2_pop_threshold & gdata$population>population_threshold),gdata$location,FUN=function(x) cumsum(x)) gdata_n<-gdata[(gdata$dtot_n>0) %in% TRUE,] gdata_n$location<-factor(gdata_n$location) gdata_n_i6<-tapply(gdata_n$cases_2_pop,list(gdata_n$dtot_n,gdata_n$location), mean, na.rm=TRUE) vmax<-data.frame(apply(as.data.frame(gdata_n_i6),2,function(x) max(x,na.rm=TRUE))) colnames(vmax)<-"max" vmax$rank<-rank(-vmax$max) vmax$location<-row.names(vmax) vmax$row<-cumsum(1-is.na(row.names(vmax))) gdata_n_i6<-gdata_n_i6[,vmax$row[vmax$rank<=25]] matplot(gdata_n_i6,pch=my_pch,col=my_col,ylab="Cases for 10,000 inhabitants (log scale)", xlim = c(0,nrow(gdata_n_i6)+10), log="y", las = 1,cex.axis=0.8,xlab=label_cases_2_pop) matlines(gdata_n_i6,col=my_col) title(main=paste(country,"-",unit,": 1. Cases for 10,000 inhabitants on",my_last_date)) legend("bottomright",bg="transparent",legend=colnames(gdata_n_i6),col=my_col, text.col = my_col,box.lwd=-1, lty=1, pch=my_pch,ncol=1,cex=0.8) #NEW CASES 2 POP SINCE TOTAL CASES ABOVE THRESHOLD gdata$new_cases_2_pop<-10000*gdata$new_cases_7/gdata$population gdata$dtot_n<-ave((ifelse(is.na(gdata$cases_2_pop),0,gdata$cases_2_pop)>cases_2_pop_threshold & gdata$population>population_threshold),gdata$location,FUN=function(x) cumsum(x)) gdata_n<-gdata[(gdata$dtot_n>0) %in% TRUE,] gdata_n$location<-factor(gdata_n$location) gdata_n_i6<-tapply(gdata_n$new_cases_2_pop,list(gdata_n$dtot_n,gdata_n$location), mean, na.rm=TRUE) gdata_n_i6<-gdata_n_i6[,vmax$row[vmax$rank<=25]] # gdata_n_spe<-gdata_n_i6[,c("LK Ennepe-Ruhr-Kreis","SK Wuppertal")] matplot(gdata_n_i6,pch=my_pch,col=my_col,ylab="New cases for 10,000 inhabitants (7-day moving average - log scale)", log="y", las = 1,cex.axis=0.8,xlab=label_cases_2_pop,xlim = c(0,nrow(gdata_n_i6)+10)) matlines(gdata_n_i6,col=my_col) title(main=paste(country,"-",unit,": 2. New cases for 10,000 inhabitants on",my_last_date)) legend("bottomright",bg="transparent",legend=colnames(gdata_n_i6),col=my_col, text.col = my_col,box.lwd=-1, lty=1, pch=my_pch,ncol=1,cex=0.8) #TOTAL DEATHS 2 POP SINCE TOTAL DEATHS ABOVE THRESHOLD gdata$dtot_n<-ave((ifelse(is.na(gdata$deaths_2_pop),0,gdata$deaths_2_pop)>death_2_pop_threshold & gdata$population>population_threshold),gdata$location,FUN=function(x) cumsum(x)) gdata_n<-gdata[(gdata$dtot_n>0) %in% TRUE,] gdata_n$location<-factor(gdata_n$location) gdata_n_i6<-tapply(gdata_n$deaths_2_pop,list(gdata_n$dtot_n,gdata_n$location), mean, na.rm=TRUE) vmax<-data.frame(apply(as.data.frame(gdata_n_i6),2,function(x) max(x,na.rm=TRUE))) colnames(vmax)<-"max" vmax$rank<-rank(-vmax$max) vmax$location<-row.names(vmax) vmax$row<-cumsum(1-is.na(row.names(vmax))) dmax<-vmax gdata_n_i6<-gdata_n_i6[,vmax$row[vmax$rank<=25]] matplot(gdata_n_i6,pch=my_pch,col=my_col,ylab="Deaths for 100,000 inhabitants (log scale)", log="y", las = 1,cex.axis=0.8,xlab=label_death_2_pop,xlim = c(0,nrow(gdata_n_i6)+10)) matlines(gdata_n_i6,col=my_col) title(main=paste(country,"-",unit,": 3. Deaths for 100,000 inhabitants on",my_last_date)) legend("bottomright",bg="transparent",legend=colnames(gdata_n_i6),col=my_col, text.col = my_col,box.lwd=-1, lty=1, pch=my_pch,ncol=1,cex=0.8) #New DEATHS 2 POP SINCE TOTAL DEATHS ABOVE THRESHOLD gdata$new_deaths_2_pop<-100000*gdata$new_deaths_7/gdata$population gdata$dtot_n<-ave((ifelse(is.na(gdata$deaths_2_pop),0,gdata$deaths_2_pop)>death_2_pop_threshold & gdata$population>population_threshold),gdata$location,FUN=function(x) cumsum(x)) gdata_n<-gdata[(gdata$dtot_n>0) %in% TRUE,] gdata_n$location<-factor(gdata_n$location) gdata_n_i6<-tapply(gdata_n$new_deaths_2_pop,list(gdata_n$dtot_n,gdata_n$location), mean, na.rm=TRUE) gdata_n_i6<-gdata_n_i6[,vmax$row[vmax$rank<=25]] matplot(gdata_n_i6,pch=my_pch,col=my_col,ylab="New deaths for 100,000 inhabitants (7-day moving average - log scale)", log="y", las = 1,cex.axis=0.8,xlab=label_death_2_pop,xlim = c(0,nrow(gdata_n_i6)+10)) matlines(gdata_n_i6,col=my_col) title(main=paste(country,"-",unit,": 4. New deaths for 100,000 inhabitants on",my_last_date)) legend("bottomright",bg="transparent",legend=colnames(gdata_n_i6),col=my_col, text.col = my_col,box.lwd=-1, lty=1, pch=my_pch,ncol=1,cex=0.8) #LETALITY DEATHS 2 CASES SINCE TOTAL DEATHS ABOVE THRESHOLD gdata$deaths_2_cases<-100*gdata$total_deaths/gdata$total_cases gdata$dtot_n<-ave((ifelse(is.na(gdata$deaths_2_pop),0,gdata$deaths_2_pop)>death_2_pop_threshold & gdata$population>population_threshold),gdata$location,FUN=function(x) cumsum(x)) gdata_n<-gdata[(gdata$dtot_n>0) %in% TRUE,] gdata_n$location<-factor(gdata_n$location) gdata_n_i6<-tapply(gdata_n$deaths_2_cases,list(gdata_n$dtot_n,gdata_n$location), mean, na.rm=TRUE) gdata_n_i6<-gdata_n_i6[,vmax$row[vmax$rank<=25]] matplot(gdata_n_i6,pch=my_pch,col=my_col,ylab="Deaths for 100 cases (log scale)", log="y", las = 1,cex.axis=0.8,xlab=label_death_2_pop,xlim = c(0,nrow(gdata_n_i6)+10)) matlines(gdata_n_i6,col=my_col) title(main=paste(country,"-",unit,": 5. Deaths for 100 cases on",my_last_date)) legend("bottomright",bg="transparent",legend=colnames(gdata_n_i6),col=my_col, text.col = my_col,box.lwd=-1, lty=1, pch=my_pch,ncol=1,cex=0.8) ######################################################## #Spain COVID GRAPHS ######################################################## gdata<-spain country<-"Spain" unit<-"Regions" case_threshold<-spain_case_threshold death_threshold<-spain_death_threshold population_threshold<-spain_population_threshold death_2_pop_threshold<-spain_death_2_pop_threshold cases_2_pop_threshold<-spain_cases_2_pop_threshold label_cases<-paste("Days since number of cases >",case_threshold) label_death<-paste("Days since number of deaths >",death_threshold) label_death_2_pop<-paste("Days since number of deaths for 100,000 inhabitants >",death_2_pop_threshold) label_cases_2_pop<-paste("Days since number of cases for 10,000 inhabitants >",cases_2_pop_threshold) my_last_date<-substr(as.vector(as.data.frame(table(gdata$date))[length(table(gdata$date)),"Var1"]),1,10) gdata$new_cases_7<-rowMeans(data.frame(gdata$new_cases, simplelag(gdata$new_cases,gdata$location,mylag = 1,outside =0), simplelag(gdata$new_cases,gdata$location,mylag = 2,outside =0), simplelag(gdata$new_cases,gdata$location,mylag = 3,outside =0), simplelag(gdata$new_cases,gdata$location,mylag = 4,outside =0), simplelag(gdata$new_cases,gdata$location,mylag = 5,outside =0), simplelag(gdata$new_cases,gdata$location,mylag = 6,outside =0)),na.rm=TRUE) gdata$new_deaths_7<-rowMeans(cbind(gdata$new_deaths, simplelag(gdata$new_deaths,gdata$location,mylag = 1,outside =0), simplelag(gdata$new_deaths,gdata$location,mylag = 2,outside =0), simplelag(gdata$new_deaths,gdata$location,mylag = 3,outside =0), simplelag(gdata$new_deaths,gdata$location,mylag = 4,outside =0), simplelag(gdata$new_deaths,gdata$location,mylag = 5,outside =0), simplelag(gdata$new_deaths,gdata$location,mylag = 6,outside =0)),na.rm = TRUE) ##TOTAL CASES 2 POP SINCE TOTAL CASES ABOVE THRESHOLD gdata$dtot_n<-ave((ifelse(is.na(gdata$cases_2_pop),0,gdata$cases_2_pop)>cases_2_pop_threshold & gdata$population>population_threshold),gdata$location,FUN=function(x) cumsum(x)) gdata_n<-gdata[(gdata$dtot_n>0) %in% TRUE,] gdata_n$location<-factor(gdata_n$location) gdata_n_i6<-tapply(gdata_n$cases_2_pop,list(gdata_n$dtot_n,gdata_n$location), mean, na.rm=TRUE) vmax<-data.frame(apply(as.data.frame(gdata_n_i6),2,function(x) max(x,na.rm=TRUE))) colnames(vmax)<-"max" vmax$rank<-rank(-vmax$max) vmax$location<-row.names(vmax) vmax$row<-cumsum(1-is.na(row.names(vmax))) gdata_n_i6<-gdata_n_i6[,vmax$row[vmax$rank<=25]] matplot(gdata_n_i6,pch=my_pch,col=my_col,ylab="Cases for 10,000 inhabitants (log scale)", xlim = c(0,nrow(gdata_n_i6)+10), log="y", las = 1,cex.axis=0.8,xlab=label_cases_2_pop) matlines(gdata_n_i6,col=my_col) title(main=paste(country,"-",unit,": 1. Cases for 10,000 inhabitants on",my_last_date)) legend("bottomright",bg="transparent",legend=colnames(gdata_n_i6),col=my_col, text.col = my_col,box.lwd=-1, lty=1, pch=my_pch,ncol=1,cex=0.8) #NEW CASES 2 POP SINCE TOTAL CASES ABOVE THRESHOLD gdata$new_cases_2_pop<-10000*gdata$new_cases_7/gdata$population gdata$dtot_n<-ave((ifelse(is.na(gdata$cases_2_pop),0,gdata$cases_2_pop)>cases_2_pop_threshold & gdata$population>population_threshold),gdata$location,FUN=function(x) cumsum(x)) gdata_n<-gdata[(gdata$dtot_n>0) %in% TRUE,] gdata_n$location<-factor(gdata_n$location) gdata_n_i6<-tapply(gdata_n$new_cases_2_pop,list(gdata_n$dtot_n,gdata_n$location), mean, na.rm=TRUE) gdata_n_i6<-gdata_n_i6[,vmax$row[vmax$rank<=25]] # gdata_n_spe<-gdata_n_i6[,c("LK Ennepe-Ruhr-Kreis","SK Wuppertal")] matplot(gdata_n_i6,pch=my_pch,col=my_col,ylab="New cases for 10,000 inhabitants (7-day moving average - log scale)", log="y", las = 1,cex.axis=0.8,xlab=label_cases_2_pop,xlim = c(0,nrow(gdata_n_i6)+10)) matlines(gdata_n_i6,col=my_col) title(main=paste(country,"-",unit,": 2. New cases for 10,000 inhabitants on",my_last_date)) legend("bottomright",bg="transparent",legend=colnames(gdata_n_i6),col=my_col, text.col = my_col,box.lwd=-1, lty=1, pch=my_pch,ncol=1,cex=0.8) #TOTAL DEATHS 2 POP SINCE TOTAL DEATHS ABOVE THRESHOLD gdata$dtot_n<-ave((ifelse(is.na(gdata$deaths_2_pop),0,gdata$deaths_2_pop)>death_2_pop_threshold & gdata$population>population_threshold),gdata$location,FUN=function(x) cumsum(x)) gdata_n<-gdata[(gdata$dtot_n>0) %in% TRUE,] gdata_n$location<-factor(gdata_n$location) gdata_n_i6<-tapply(gdata_n$deaths_2_pop,list(gdata_n$dtot_n,gdata_n$location), mean, na.rm=TRUE) vmax<-data.frame(apply(as.data.frame(gdata_n_i6),2,function(x) max(x,na.rm=TRUE))) colnames(vmax)<-"max" vmax$rank<-rank(-vmax$max) vmax$location<-row.names(vmax) vmax$row<-cumsum(1-is.na(row.names(vmax))) dmax<-vmax gdata_n_i6<-gdata_n_i6[,vmax$row[vmax$rank<=25]] matplot(gdata_n_i6,pch=my_pch,col=my_col,ylab="Deaths for 100,000 inhabitants (log scale)", log="y", las = 1,cex.axis=0.8,xlab=label_death_2_pop,xlim = c(0,nrow(gdata_n_i6)+10)) matlines(gdata_n_i6,col=my_col) title(main=paste(country,"-",unit,": 3. Deaths for 100,000 inhabitants on",my_last_date)) legend("bottomright",bg="transparent",legend=colnames(gdata_n_i6),col=my_col, text.col = my_col,box.lwd=-1, lty=1, pch=my_pch,ncol=1,cex=0.8) #New DEATHS 2 POP SINCE TOTAL DEATHS ABOVE THRESHOLD gdata$new_deaths_2_pop<-100000*gdata$new_deaths_7/gdata$population gdata$dtot_n<-ave((ifelse(is.na(gdata$deaths_2_pop),0,gdata$deaths_2_pop)>death_2_pop_threshold & gdata$population>population_threshold),gdata$location,FUN=function(x) cumsum(x)) gdata_n<-gdata[(gdata$dtot_n>0) %in% TRUE,] gdata_n$location<-factor(gdata_n$location) gdata_n_i6<-tapply(gdata_n$new_deaths_2_pop,list(gdata_n$dtot_n,gdata_n$location), mean, na.rm=TRUE) gdata_n_i6<-gdata_n_i6[,vmax$row[vmax$rank<=25]] matplot(gdata_n_i6,pch=my_pch,col=my_col,ylab="New deaths for 100,000 inhabitants (7-day moving average - log scale)", log="y", las = 1,cex.axis=0.8,xlab=label_death_2_pop,xlim = c(0,nrow(gdata_n_i6)+10)) matlines(gdata_n_i6,col=my_col) title(main=paste(country,"-",unit,": 4. New deaths for 100,000 inhabitants on",my_last_date)) legend("bottomright",bg="transparent",legend=colnames(gdata_n_i6),col=my_col, text.col = my_col,box.lwd=-1, lty=1, pch=my_pch,ncol=1,cex=0.8) #LETALITY DEATHS 2 CASES SINCE TOTAL DEATHS ABOVE THRESHOLD gdata$deaths_2_cases<-100*gdata$total_deaths/gdata$total_cases gdata$dtot_n<-ave((ifelse(is.na(gdata$deaths_2_pop),0,gdata$deaths_2_pop)>death_2_pop_threshold & gdata$population>population_threshold),gdata$location,FUN=function(x) cumsum(x)) gdata_n<-gdata[(gdata$dtot_n>0) %in% TRUE,] gdata_n$location<-factor(gdata_n$location) gdata_n_i6<-tapply(gdata_n$deaths_2_cases,list(gdata_n$dtot_n,gdata_n$location), mean, na.rm=TRUE) gdata_n_i6<-gdata_n_i6[,vmax$row[vmax$rank<=25]] matplot(gdata_n_i6,pch=my_pch,col=my_col,ylab="Deaths for 100 cases (log scale)", log="y", las = 1,cex.axis=0.8,xlab=label_death_2_pop,xlim = c(0,nrow(gdata_n_i6)+10)) matlines(gdata_n_i6,col=my_col) title(main=paste(country,"-",unit,": 5. Deaths for 100 cases on",my_last_date)) legend("bottomright",bg="transparent",legend=colnames(gdata_n_i6),col=my_col, text.col = my_col,box.lwd=-1, lty=1, pch=my_pch,ncol=1,cex=0.8) #Hospitalization gdata$dtot_n<-ave((ifelse(is.na(gdata$deaths_2_pop),0,gdata$deaths_2_pop)>death_2_pop_threshold & gdata$population>population_threshold),gdata$location,FUN=function(x) cumsum(x)) gdata_n<-gdata[(gdata$dtot_n>0) %in% TRUE,] gdata_n$location<-factor(gdata_n$location) gdata_n_i6<-tapply(10000*gdata_n$hospitalization,list(gdata_n$dtot_n,gdata_n$location), mean, na.rm=TRUE) matplot(gdata_n_i6,pch=my_pch,col=my_col,ylab="Hospitalization for 10 000 inhabitants (log scale)", log="y", las = 1,cex.axis=0.8,xlab=label_death_2_pop,xlim = c(0,nrow(gdata_n_i6)+10)) matlines(gdata_n_i6,col=my_col) title(main=paste(country,"-",unit,": 6. Hospitalization for 10 000 inhabitants on",my_last_date)) legend("bottomright",bg="transparent",legend=colnames(gdata_n_i6),col=my_col, text.col = my_col,box.lwd=-1, lty=1, pch=my_pch,ncol=1,cex=0.8) #Variation in hospitalization gdata$hospitalization_evol_7<-(rowMeans(cbind(gdata$population*gdata$hospitalization_evol, gdata$population*simplelag(gdata$hospitalization_evol,gdata$location,mylag = 1,outside =0), gdata$population*simplelag(gdata$hospitalization_evol,gdata$location,mylag = 2,outside =0), gdata$population*simplelag(gdata$hospitalization_evol,gdata$location,mylag = 3,outside =0), gdata$population*simplelag(gdata$hospitalization_evol,gdata$location,mylag = 4,outside =0), gdata$population*simplelag(gdata$hospitalization_evol,gdata$location,mylag = 5,outside =0), gdata$population*simplelag(gdata$hospitalization_evol,gdata$location,mylag = 6,outside =0),na.rm=TRUE)))/gdata$population gdata$dtot_n<-ave((ifelse(is.na(gdata$deaths_2_pop),0,gdata$deaths_2_pop)>death_2_pop_threshold & gdata$population>population_threshold),gdata$location,FUN=function(x) cumsum(x)) gdata_n<-gdata[(gdata$dtot_n>0) %in% TRUE,] gdata_n$location<-factor(gdata_n$location) gdata_n_i6<-tapply(10000*gdata_n$hospitalization_evol_7,list(gdata_n$dtot_n,gdata_n$location), mean, na.rm=TRUE) matplot(gdata_n_i6,pch=my_pch,col=my_col,ylab="Variation in hospitalization for 10 000 inhabitants (7-day moving average)", las = 1,cex.axis=0.8,xlab=label_death_2_pop,xlim = c(0,nrow(gdata_n_i6)+10)) matlines(gdata_n_i6,col=my_col) title(main=paste(country,"-",unit,": 7. Variation in hospitalization for 10 000 inhabitants",my_last_date)) abline(h=0,col="darkgray") legend("topright",bg="transparent",legend=colnames(gdata_n_i6),col=my_col, text.col = my_col,box.lwd=-1, lty=1, pch=my_pch,ncol=1,cex=0.8) #Reanimation gdata$dtot_n<-ave((ifelse(is.na(gdata$deaths_2_pop),0,gdata$deaths_2_pop)>death_2_pop_threshold & gdata$population>population_threshold),gdata$location,FUN=function(x) cumsum(x)) gdata_n<-gdata[(gdata$dtot_n>0) %in% TRUE,] gdata_n$location<-factor(gdata_n$location) gdata_n_i6<-tapply(10000*gdata_n$reanimation,list(gdata_n$dtot_n,gdata_n$location), mean, na.rm=TRUE) matplot(gdata_n_i6,pch=my_pch,col=my_col,ylab="Reanimation for 10 000 inhabitants (log scale)", log="y", las = 1,cex.axis=0.8,xlab=label_death_2_pop,xlim = c(0,nrow(gdata_n_i6)+10)) matlines(gdata_n_i6,col=my_col) title(main=paste(country,"-",unit,": 8. Reanimation for 10 000 inhabitants on",my_last_date)) legend("bottomright",bg="transparent",legend=colnames(gdata_n_i6),col=my_col, text.col = my_col,box.lwd=-1, lty=1, pch=my_pch,ncol=1,cex=0.8) #Variation in reanimation gdata$reanimation_evol_7<-(rowMeans(cbind(gdata$population*gdata$reanimation_evol, gdata$population*simplelag(gdata$reanimation_evol,gdata$location,mylag = 1,outside =0), gdata$population*simplelag(gdata$reanimation_evol,gdata$location,mylag = 2,outside =0), gdata$population*simplelag(gdata$reanimation_evol,gdata$location,mylag = 3,outside =0), gdata$population*simplelag(gdata$reanimation_evol,gdata$location,mylag = 4,outside =0), gdata$population*simplelag(gdata$reanimation_evol,gdata$location,mylag = 5,outside =0), gdata$population*simplelag(gdata$reanimation_evol,gdata$location,mylag = 6,outside =0),na.rm=TRUE)))/gdata$population gdata$dtot_n<-ave((ifelse(is.na(gdata$deaths_2_pop),0,gdata$deaths_2_pop)>death_2_pop_threshold & gdata$population>population_threshold),gdata$location,FUN=function(x) cumsum(x)) gdata_n<-gdata[(gdata$dtot_n>0) %in% TRUE,] gdata_n$location<-factor(gdata_n$location) gdata_n_i6<-tapply(10000*gdata_n$reanimation_evol_7,list(gdata_n$dtot_n,gdata_n$location), mean, na.rm=TRUE) matplot(gdata_n_i6,pch=my_pch,col=my_col,ylab="Variation in reanimation for 10 000 inhabitants (7-day moving average)", las = 1,cex.axis=0.8,xlab=label_death_2_pop,xlim = c(0,nrow(gdata_n_i6)+10)) matlines(gdata_n_i6,col=my_col) title(main=paste(country,"-",unit,": 9. Variation in reanimation for 10 000 inhabitants",my_last_date)) abline(h=0,col="darkgray") legend("topright",bg="transparent",legend=colnames(gdata_n_i6),col=my_col, text.col = my_col,box.lwd=-1, lty=1, pch=my_pch,ncol=1,cex=0.8) ################################################### #FRENCH COVID GRAPHS ################################################### ################################################### #French Region Graphs gdata<-france_reg country<-"France" unit<-"Regions" case_threshold<-france_reg_case_threshold death_threshold<-france_reg_death_threshold population_threshold<-france_reg_population_threshold death_2_pop_threshold<-france_reg_death_2_pop_threshold cases_2_pop_threshold<-france_reg_cases_2_pop_threshold label_cases<-paste("Days since number of cases >",case_threshold) label_death<-paste("Days since number of deaths >",death_threshold) label_death_2_pop<-paste("Days since number of deaths for 100,000 inhabitants >",death_2_pop_threshold) label_cases_2_pop<-paste("Days since number of cases for 10,000 inhabitants >",cases_2_pop_threshold) my_last_date<-as.vector(as.data.frame(table(gdata$date))[length(table(gdata$date)),"Var1"]) gdata$new_cases_7<-rowMeans(data.frame(gdata$new_cases, simplelag(gdata$new_cases,gdata$location,mylag = 1,outside =0), simplelag(gdata$new_cases,gdata$location,mylag = 2,outside =0), simplelag(gdata$new_cases,gdata$location,mylag = 3,outside =0), simplelag(gdata$new_cases,gdata$location,mylag = 4,outside =0), simplelag(gdata$new_cases,gdata$location,mylag = 5,outside =0), simplelag(gdata$new_cases,gdata$location,mylag = 6,outside =0)),na.rm=TRUE) gdata$new_deaths_7<-rowMeans(cbind(gdata$new_deaths, simplelag(gdata$new_deaths,gdata$location,mylag = 1,outside =0), simplelag(gdata$new_deaths,gdata$location,mylag = 2,outside =0), simplelag(gdata$new_deaths,gdata$location,mylag = 3,outside =0), simplelag(gdata$new_deaths,gdata$location,mylag = 4,outside =0), simplelag(gdata$new_deaths,gdata$location,mylag = 5,outside =0), simplelag(gdata$new_deaths,gdata$location,mylag = 6,outside =0)),na.rm = TRUE) ##TOTAL CASES 2 POP SINCE TOTAL CASES ABOVE THRESHOLD gdata$dtot_n<-ave((ifelse(is.na(gdata$cases_2_pop),0,gdata$cases_2_pop)>cases_2_pop_threshold & gdata$population>population_threshold),gdata$location,FUN=function(x) cumsum(x)) gdata_n<-gdata[(gdata$dtot_n>0) %in% TRUE,] gdata_n$location<-factor(gdata_n$location) gdata_n_i6<-tapply(gdata_n$cases_2_pop,list(gdata_n$dtot_n,gdata_n$location), mean, na.rm=TRUE) vmax<-data.frame(apply(as.data.frame(gdata_n_i6),2,function(x) max(x,na.rm=TRUE))) colnames(vmax)<-"max" vmax$rank<-rank(-vmax$max) vmax$location<-row.names(vmax) vmax$row<-cumsum(1-is.na(row.names(vmax))) gdata_n_i6<-gdata_n_i6[,vmax$row[vmax$rank<=25]] matplot(gdata_n_i6,pch=my_pch,col=my_col,ylab="Cases for 10,000 inhabitants (log scale)", xlim = c(0,nrow(gdata_n_i6)+10), log="y", las = 1,cex.axis=0.8,xlab=label_cases_2_pop) matlines(gdata_n_i6,col=my_col) title(main=paste(country,"-",unit,": 1. Cases for 10,000 inhabitants on",my_last_date)) legend("bottomright",bg="transparent",legend=colnames(gdata_n_i6),col=my_col, text.col = my_col,box.lwd=-1, lty=1, pch=my_pch,ncol=1,cex=0.8) #NEW CASES 2 POP SINCE TOTAL CASES ABOVE THRESHOLD gdata$new_cases_2_pop<-10000*gdata$new_cases_7/gdata$population gdata$dtot_n<-ave((ifelse(is.na(gdata$cases_2_pop),0,gdata$cases_2_pop)>cases_2_pop_threshold & gdata$population>population_threshold),gdata$location,FUN=function(x) cumsum(x)) gdata_n<-gdata[(gdata$dtot_n>0) %in% TRUE,] gdata_n$location<-factor(gdata_n$location) gdata_n_i6<-tapply(gdata_n$new_cases_2_pop,list(gdata_n$dtot_n,gdata_n$location), mean, na.rm=TRUE) gdata_n_i6<-gdata_n_i6[,vmax$row[vmax$rank<=25]] matplot(gdata_n_i6,pch=my_pch,col=my_col,ylab="New cases for 10,000 inhabitants (7-day moving average - log scale)", log="y", las = 1,cex.axis=0.8,xlab=label_cases_2_pop,xlim = c(0,nrow(gdata_n_i6)+10)) matlines(gdata_n_i6,col=my_col) title(main=paste(country,"-",unit,": 2. New cases for 10,000 inhabitants on",my_last_date)) legend("bottomright",bg="transparent",legend=colnames(gdata_n_i6),col=my_col, text.col = my_col,box.lwd=-1, lty=1, pch=my_pch,ncol=1,cex=0.8) #TOTAL DEATHS 2 POP SINCE TOTAL DEATHS ABOVE THRESHOLD gdata$dtot_n<-ave((ifelse(is.na(gdata$deaths_2_pop),0,gdata$deaths_2_pop)>death_2_pop_threshold & gdata$population>population_threshold),gdata$location,FUN=function(x) cumsum(x)) gdata_n<-gdata[(gdata$dtot_n>0) %in% TRUE,] gdata_n$location<-factor(gdata_n$location) gdata_n_i6<-tapply(gdata_n$deaths_2_pop,list(gdata_n$dtot_n,gdata_n$location), mean, na.rm=TRUE) vmax<-data.frame(apply(as.data.frame(gdata_n_i6),2,function(x) max(x,na.rm=TRUE))) colnames(vmax)<-"max" vmax$rank<-rank(-vmax$max) vmax$location<-row.names(vmax) vmax$row<-cumsum(1-is.na(row.names(vmax))) dmax<-vmax gdata_n_i6<-gdata_n_i6[,vmax$row[vmax$rank<=25]] matplot(gdata_n_i6,pch=my_pch,col=my_col,ylab="Deaths for 100,000 inhabitants (log scale)", log="y", las = 1,cex.axis=0.8,xlab=label_death_2_pop,xlim = c(0,nrow(gdata_n_i6)+10)) matlines(gdata_n_i6,col=my_col) title(main=paste(country,"-",unit,": 3. Deaths for 100,000 inhabitants on",my_last_date)) legend("bottomright",bg="transparent",legend=colnames(gdata_n_i6),col=my_col, text.col = my_col,box.lwd=-1, lty=1, pch=my_pch,ncol=1,cex=0.8) #New DEATHS 2 POP SINCE TOTAL DEATHS ABOVE THRESHOLD gdata$new_deaths_2_pop<-100000*gdata$new_deaths_7/gdata$population gdata$dtot_n<-ave((ifelse(is.na(gdata$deaths_2_pop),0,gdata$deaths_2_pop)>death_2_pop_threshold & gdata$population>population_threshold),gdata$location,FUN=function(x) cumsum(x)) gdata_n<-gdata[(gdata$dtot_n>0) %in% TRUE,] gdata_n$location<-factor(gdata_n$location) gdata_n_i6<-tapply(gdata_n$new_deaths_2_pop,list(gdata_n$dtot_n,gdata_n$location), mean, na.rm=TRUE) gdata_n_i6<-gdata_n_i6[,vmax$row[vmax$rank<=25]] matplot(gdata_n_i6,pch=my_pch,col=my_col,ylab="New deaths for 100,000 inhabitants (7-day moving average - log scale)", log="y", las = 1,cex.axis=0.8,xlab=label_death_2_pop,xlim = c(0,nrow(gdata_n_i6)+10)) matlines(gdata_n_i6,col=my_col) title(main=paste(country,"-",unit,": 4. New deaths for 100,000 inhabitants on",my_last_date)) legend("bottomright",bg="transparent",legend=colnames(gdata_n_i6),col=my_col, text.col = my_col,box.lwd=-1, lty=1, pch=my_pch,ncol=1,cex=0.8) #LETALITY DEATHS 2 CASES SINCE TOTAL DEATHS ABOVE THRESHOLD gdata$deaths_2_cases<-100*gdata$total_deaths/gdata$total_cases gdata$dtot_n<-ave((ifelse(is.na(gdata$deaths_2_pop),0,gdata$deaths_2_pop)>death_2_pop_threshold & gdata$population>population_threshold),gdata$location,FUN=function(x) cumsum(x)) gdata_n<-gdata[(gdata$dtot_n>0) %in% TRUE,] gdata_n$location<-factor(gdata_n$location) gdata_n_i6<-tapply(gdata_n$deaths_2_cases,list(gdata_n$dtot_n,gdata_n$location), mean, na.rm=TRUE) gdata_n_i6<-gdata_n_i6[,vmax$row[vmax$rank<=25]] matplot(gdata_n_i6,pch=my_pch,col=my_col,ylab="Deaths for 100 cases (log scale)", log="y", las = 1,cex.axis=0.8,xlab=label_death_2_pop,xlim = c(0,nrow(gdata_n_i6)+10)) matlines(gdata_n_i6,col=my_col) title(main=paste(country,"-",unit,": 5. Deaths for 100 cases on",my_last_date)) legend("bottomright",bg="transparent",legend=colnames(gdata_n_i6),col=my_col, text.col = my_col,box.lwd=-1, lty=1, pch=my_pch,ncol=1,cex=0.8) #Hospitalization gdata$dtot_n<-ave((ifelse(is.na(gdata$deaths_2_pop),0,gdata$deaths_2_pop)>death_2_pop_threshold & gdata$population>population_threshold),gdata$location,FUN=function(x) cumsum(x)) gdata_n<-gdata[(gdata$dtot_n>0) %in% TRUE,] gdata_n$location<-factor(gdata_n$location) gdata_n_i6<-tapply(10000*gdata_n$hospitalization,list(gdata_n$dtot_n,gdata_n$location), mean, na.rm=TRUE) matplot(gdata_n_i6,pch=my_pch,col=my_col,ylab="Hospitalization for 10 000 inhabitants (log scale)", log="y", las = 1,cex.axis=0.8,xlab=label_death_2_pop,xlim = c(0,nrow(gdata_n_i6)+10)) matlines(gdata_n_i6,col=my_col) title(main=paste(country,"-",unit,": 6. Hospitalization for 10 000 inhabitants on",my_last_date)) legend("bottomright",bg="transparent",legend=colnames(gdata_n_i6),col=my_col, text.col = my_col,box.lwd=-1, lty=1, pch=my_pch,ncol=1,cex=0.8) #Variation in hospitalization gdata$hospitalization_evol_7<-(rowMeans(cbind(gdata$population*gdata$hospitalization_evol, gdata$population*simplelag(gdata$hospitalization_evol,gdata$location,mylag = 1,outside =0), gdata$population*simplelag(gdata$hospitalization_evol,gdata$location,mylag = 2,outside =0), gdata$population*simplelag(gdata$hospitalization_evol,gdata$location,mylag = 3,outside =0), gdata$population*simplelag(gdata$hospitalization_evol,gdata$location,mylag = 4,outside =0), gdata$population*simplelag(gdata$hospitalization_evol,gdata$location,mylag = 5,outside =0), gdata$population*simplelag(gdata$hospitalization_evol,gdata$location,mylag = 6,outside =0),na.rm=TRUE)))/gdata$population gdata$dtot_n<-ave((ifelse(is.na(gdata$deaths_2_pop),0,gdata$deaths_2_pop)>death_2_pop_threshold & gdata$population>population_threshold),gdata$location,FUN=function(x) cumsum(x)) gdata_n<-gdata[(gdata$dtot_n>0) %in% TRUE,] gdata_n$location<-factor(gdata_n$location) gdata_n_i6<-tapply(10000*gdata_n$hospitalization_evol_7,list(gdata_n$dtot_n,gdata_n$location), mean, na.rm=TRUE) matplot(gdata_n_i6,pch=my_pch,col=my_col,ylab="Variation in hospitalization for 10 000 inhabitants (7-day moving average)", las = 1,cex.axis=0.8,xlab=label_death_2_pop,xlim = c(0,nrow(gdata_n_i6)+10)) matlines(gdata_n_i6,col=my_col) title(main=paste(country,"-",unit,": 7. Variation in hospitalization for 10 000 inhabitants",my_last_date)) abline(h=0,col="darkgray") legend("topright",bg="transparent",legend=colnames(gdata_n_i6),col=my_col, text.col = my_col,box.lwd=-1, lty=1, pch=my_pch,ncol=1,cex=0.8) #Reanimation gdata$dtot_n<-ave((ifelse(is.na(gdata$deaths_2_pop),0,gdata$deaths_2_pop)>death_2_pop_threshold & gdata$population>population_threshold),gdata$location,FUN=function(x) cumsum(x)) gdata_n<-gdata[(gdata$dtot_n>0) %in% TRUE,] gdata_n$location<-factor(gdata_n$location) gdata_n_i6<-tapply(10000*gdata_n$reanimation,list(gdata_n$dtot_n,gdata_n$location), mean, na.rm=TRUE) matplot(gdata_n_i6,pch=my_pch,col=my_col,ylab="Reanimation for 10 000 inhabitants (log scale)", log="y", las = 1,cex.axis=0.8,xlab=label_death_2_pop,xlim = c(0,nrow(gdata_n_i6)+10)) matlines(gdata_n_i6,col=my_col) title(main=paste(country,"-",unit,": 8. Reanimation for 10 000 inhabitants on",my_last_date)) legend("bottomright",bg="transparent",legend=colnames(gdata_n_i6),col=my_col, text.col = my_col,box.lwd=-1, lty=1, pch=my_pch,ncol=1,cex=0.8) #Reanimation variation gdata$reanimation_evol_7<-(rowMeans(cbind(gdata$population*gdata$reanimation_evol, gdata$population*simplelag(gdata$reanimation_evol,gdata$location,mylag = 1,outside =0), gdata$population*simplelag(gdata$reanimation_evol,gdata$location,mylag = 2,outside =0), gdata$population*simplelag(gdata$reanimation_evol,gdata$location,mylag = 3,outside =0), gdata$population*simplelag(gdata$reanimation_evol,gdata$location,mylag = 4,outside =0), gdata$population*simplelag(gdata$reanimation_evol,gdata$location,mylag = 5,outside =0), gdata$population*simplelag(gdata$reanimation_evol,gdata$location,mylag = 6,outside =0),na.rm=TRUE)))/gdata$population gdata$dtot_n<-ave((ifelse(is.na(gdata$deaths_2_pop),0,gdata$deaths_2_pop)>death_2_pop_threshold & gdata$population>population_threshold),gdata$location,FUN=function(x) cumsum(x)) gdata_n<-gdata[(gdata$dtot_n>0) %in% TRUE,] gdata_n$location<-factor(gdata_n$location) gdata_n_i6<-tapply(10000*gdata_n$reanimation_evol_7,list(gdata_n$dtot_n,gdata_n$location), mean, na.rm=TRUE) matplot(gdata_n_i6,pch=my_pch,col=my_col,ylab="Variation in reanimation for 10 000 inhabitants (7-day moving average)", las = 1,cex.axis=0.8,xlab=label_death_2_pop,xlim = c(0,nrow(gdata_n_i6)+10)) matlines(gdata_n_i6,col=my_col) title(main=paste(country,"-",unit,": 9. Variation in reanimation for 10 000 inhabitants",my_last_date)) abline(h=0,col="darkgray") legend("topright",bg="transparent",legend=colnames(gdata_n_i6),col=my_col, text.col = my_col,box.lwd=-1, lty=1, pch=my_pch,ncol=1,cex=0.8) ################################################### #French departments graphs gdata<-france_dep country<-"France" unit<-"Top 25 Departments" case_threshold<-france_dep_case_threshold death_threshold<-france_dep_death_threshold population_threshold<-france_dep_population_threshold death_2_pop_threshold<-france_dep_death_2_pop_threshold cases_2_pop_threshold<-france_dep_cases_2_pop_threshold label_cases<-paste("Days since number of cases >",case_threshold) label_death<-paste("Days since number of deaths >",death_threshold) label_death_2_pop<-paste("Days since number of deaths for 100,000 inhabitants >",death_2_pop_threshold) label_cases_2_pop<-paste("Days since number of cases for 10,000 inhabitants >",cases_2_pop_threshold) my_last_date<-as.vector(as.data.frame(table(gdata$date))[length(table(gdata$date)),"Var1"]) gdata$new_cases_7<-rowMeans(data.frame(gdata$new_cases, simplelag(gdata$new_cases,gdata$location,mylag = 1,outside =0), simplelag(gdata$new_cases,gdata$location,mylag = 2,outside =0), simplelag(gdata$new_cases,gdata$location,mylag = 3,outside =0), simplelag(gdata$new_cases,gdata$location,mylag = 4,outside =0), simplelag(gdata$new_cases,gdata$location,mylag = 5,outside =0), simplelag(gdata$new_cases,gdata$location,mylag = 6,outside =0)),na.rm=TRUE) gdata$new_deaths_7<-rowMeans(cbind(gdata$new_deaths, simplelag(gdata$new_deaths,gdata$location,mylag = 1,outside =0), simplelag(gdata$new_deaths,gdata$location,mylag = 2,outside =0), simplelag(gdata$new_deaths,gdata$location,mylag = 3,outside =0), simplelag(gdata$new_deaths,gdata$location,mylag = 4,outside =0), simplelag(gdata$new_deaths,gdata$location,mylag = 5,outside =0), simplelag(gdata$new_deaths,gdata$location,mylag = 6,outside =0)),na.rm = TRUE) ##TOTAL CASES 2 POP SINCE TOTAL CASES ABOVE THRESHOLD gdata$dtot_n<-ave((ifelse(is.na(gdata$cases_2_pop),0,gdata$cases_2_pop)>cases_2_pop_threshold & gdata$population>population_threshold),gdata$location,FUN=function(x) cumsum(x)) gdata_n<-gdata[(gdata$dtot_n>0) %in% TRUE,] gdata_n$location<-factor(gdata_n$location) gdata_n_i6<-tapply(gdata_n$cases_2_pop,list(gdata_n$dtot_n,gdata_n$location), mean, na.rm=TRUE) vmax<-data.frame(apply(as.data.frame(gdata_n_i6),2,function(x) max(x,na.rm=TRUE))) colnames(vmax)<-"max" vmax$rank<-rank(-vmax$max) vmax$location<-row.names(vmax) vmax$row<-cumsum(1-is.na(row.names(vmax))) gdata_n_i6<-gdata_n_i6[,vmax$row[vmax$rank<=25]] matplot(gdata_n_i6,pch=my_pch,col=my_col,ylab="Cases for 10,000 inhabitants (log scale)", xlim = c(0,nrow(gdata_n_i6)+10), log="y", las = 1,cex.axis=0.8,xlab=label_cases_2_pop) matlines(gdata_n_i6,col=my_col) title(main=paste(country,"-",unit,": 1. Cases for 10,000 inhabitants on",my_last_date)) legend("bottomright",bg="transparent",legend=colnames(gdata_n_i6),col=my_col, text.col = my_col,box.lwd=-1, lty=1, pch=my_pch,ncol=1,cex=0.8) #NEW CASES 2 POP SINCE TOTAL CASES ABOVE THRESHOLD gdata$new_cases_2_pop<-10000*gdata$new_cases_7/gdata$population gdata$dtot_n<-ave((ifelse(is.na(gdata$cases_2_pop),0,gdata$cases_2_pop)>cases_2_pop_threshold & gdata$population>population_threshold),gdata$location,FUN=function(x) cumsum(x)) gdata_n<-gdata[(gdata$dtot_n>0) %in% TRUE,] gdata_n$location<-factor(gdata_n$location) gdata_n_i6<-tapply(gdata_n$new_cases_2_pop,list(gdata_n$dtot_n,gdata_n$location), mean, na.rm=TRUE) gdata_n_i6<-gdata_n_i6[,vmax$row[vmax$rank<=25]] matplot(gdata_n_i6,pch=my_pch,col=my_col,ylab="New cases for 10,000 inhabitants (7-day moving average - log scale)", log="y", las = 1,cex.axis=0.8,xlab=label_cases_2_pop,xlim = c(0,nrow(gdata_n_i6)+10)) matlines(gdata_n_i6,col=my_col) title(main=paste(country,"-",unit,": 2. New cases for 10,000 inhabitants on",my_last_date)) legend("bottomright",bg="transparent",legend=colnames(gdata_n_i6),col=my_col, text.col = my_col,box.lwd=-1, lty=1, pch=my_pch,ncol=1,cex=0.8) #TOTAL DEATHS 2 POP SINCE TOTAL DEATHS ABOVE THRESHOLD gdata$dtot_n<-ave((ifelse(is.na(gdata$deaths_2_pop),0,gdata$deaths_2_pop)>death_2_pop_threshold & gdata$population>population_threshold),gdata$location,FUN=function(x) cumsum(x)) gdata_n<-gdata[(gdata$dtot_n>0) %in% TRUE,] gdata_n$location<-factor(gdata_n$location) gdata_n_i6<-tapply(gdata_n$deaths_2_pop,list(gdata_n$dtot_n,gdata_n$location), mean, na.rm=TRUE) vmax<-data.frame(apply(as.data.frame(gdata_n_i6),2,function(x) max(x,na.rm=TRUE))) colnames(vmax)<-"max" vmax$rank<-rank(-vmax$max) vmax$location<-row.names(vmax) vmax$row<-cumsum(1-is.na(row.names(vmax))) dmax<-vmax gdata_n_i6<-gdata_n_i6[,vmax$row[vmax$rank<=25]] matplot(gdata_n_i6,pch=my_pch,col=my_col,ylab="Deaths for 100,000 inhabitants (log scale)", log="y", las = 1,cex.axis=0.8,xlab=label_death_2_pop,xlim = c(0,nrow(gdata_n_i6)+10)) matlines(gdata_n_i6,col=my_col) title(main=paste(country,"-",unit,": 3. Deaths for 100,000 inhabitants on",my_last_date)) legend("bottomright",bg="transparent",legend=colnames(gdata_n_i6),col=my_col, text.col = my_col,box.lwd=-1, lty=1, pch=my_pch,ncol=1,cex=0.8) #New DEATHS 2 POP SINCE TOTAL DEATHS ABOVE THRESHOLD gdata$new_deaths_2_pop<-100000*gdata$new_deaths_7/gdata$population gdata$dtot_n<-ave((ifelse(is.na(gdata$deaths_2_pop),0,gdata$deaths_2_pop)>death_2_pop_threshold & gdata$population>population_threshold),gdata$location,FUN=function(x) cumsum(x)) gdata_n<-gdata[(gdata$dtot_n>0) %in% TRUE,] gdata_n$location<-factor(gdata_n$location) gdata_n_i6<-tapply(gdata_n$new_deaths_2_pop,list(gdata_n$dtot_n,gdata_n$location), mean, na.rm=TRUE) gdata_n_i6<-gdata_n_i6[,vmax$row[vmax$rank<=25]] matplot(gdata_n_i6,pch=my_pch,col=my_col,ylab="New deaths for 100,000 inhabitants (7-day moving average - log scale)", log="y", las = 1,cex.axis=0.8,xlab=label_death_2_pop,xlim = c(0,nrow(gdata_n_i6)+10)) matlines(gdata_n_i6,col=my_col) title(main=paste(country,"-",unit,": 4. New deaths for 100,000 inhabitants on",my_last_date)) legend("bottomright",bg="transparent",legend=colnames(gdata_n_i6),col=my_col, text.col = my_col,box.lwd=-1, lty=1, pch=my_pch,ncol=1,cex=0.8) #LETALITY DEATHS 2 CASES SINCE TOTAL DEATHS ABOVE THRESHOLD gdata$deaths_2_cases<-100*gdata$total_deaths/gdata$total_cases gdata$dtot_n<-ave((ifelse(is.na(gdata$deaths_2_pop),0,gdata$deaths_2_pop)>death_2_pop_threshold & gdata$population>population_threshold),gdata$location,FUN=function(x) cumsum(x)) gdata_n<-gdata[(gdata$dtot_n>0) %in% TRUE,] gdata_n$location<-factor(gdata_n$location) gdata_n_i6<-tapply(gdata_n$deaths_2_cases,list(gdata_n$dtot_n,gdata_n$location), mean, na.rm=TRUE) gdata_n_i6<-gdata_n_i6[,vmax$row[vmax$rank<=25]] matplot(gdata_n_i6,pch=my_pch,col=my_col,ylab="Deaths for 100 cases (log scale)", log="y", las = 1,cex.axis=0.8,xlab=label_death_2_pop,xlim = c(0,nrow(gdata_n_i6)+10)) matlines(gdata_n_i6,col=my_col) title(main=paste(country,"-",unit,": 5. Deaths for 100 cases on",my_last_date)) legend("bottomright",bg="transparent",legend=colnames(gdata_n_i6),col=my_col, text.col = my_col,box.lwd=-1, lty=1, pch=my_pch,ncol=1,cex=0.8) #Hospitalization gdata$dtot_n<-ave((ifelse(is.na(gdata$deaths_2_pop),0,gdata$deaths_2_pop)>death_2_pop_threshold & gdata$population>population_threshold),gdata$location,FUN=function(x) cumsum(x)) gdata_n<-gdata[(gdata$dtot_n>0) %in% TRUE,] gdata_n$location<-factor(gdata_n$location) gdata_n_i6<-tapply(10000*gdata_n$hospitalization,list(gdata_n$dtot_n,gdata_n$location), mean, na.rm=TRUE) gdata_n_i6<-gdata_n_i6[,vmax$row[vmax$rank<=25]] matplot(gdata_n_i6,pch=my_pch,col=my_col,ylab="Hospitalization for 10 000 inhabitants (log scale)", log="y", las = 1,cex.axis=0.8,xlab=label_death_2_pop,xlim = c(0,nrow(gdata_n_i6)+10)) matlines(gdata_n_i6,col=my_col) title(main=paste(country,"-",unit,": 6. Hospitalization for 10 000 inhabitants on",my_last_date)) legend("bottomright",bg="transparent",legend=colnames(gdata_n_i6),col=my_col, text.col = my_col,box.lwd=-1, lty=1, pch=my_pch,ncol=1,cex=0.8) #Variation in hospitalization gdata$hospitalization_evol_7<-(rowMeans(cbind(gdata$population*gdata$hospitalization_evol, gdata$population*simplelag(gdata$hospitalization_evol,gdata$location,mylag = 1,outside =0), gdata$population*simplelag(gdata$hospitalization_evol,gdata$location,mylag = 2,outside =0), gdata$population*simplelag(gdata$hospitalization_evol,gdata$location,mylag = 3,outside =0), gdata$population*simplelag(gdata$hospitalization_evol,gdata$location,mylag = 4,outside =0), gdata$population*simplelag(gdata$hospitalization_evol,gdata$location,mylag = 5,outside =0), gdata$population*simplelag(gdata$hospitalization_evol,gdata$location,mylag = 6,outside =0),na.rm=TRUE)))/gdata$population gdata$dtot_n<-ave((ifelse(is.na(gdata$deaths_2_pop),0,gdata$deaths_2_pop)>death_2_pop_threshold & gdata$population>population_threshold),gdata$location,FUN=function(x) cumsum(x)) gdata_n<-gdata[(gdata$dtot_n>0) %in% TRUE,] gdata_n$location<-factor(gdata_n$location) gdata_n_i6<-tapply(10000*gdata_n$hospitalization_evol_7,list(gdata_n$dtot_n,gdata_n$location), mean, na.rm=TRUE) gdata_n_i6<-gdata_n_i6[,vmax$row[vmax$rank<=25]] matplot(gdata_n_i6,pch=my_pch,col=my_col,ylab="Variation in hospitalization for 10 000 inhabitants (7-day moving average)", las = 1,cex.axis=0.8,xlab=label_death_2_pop,xlim = c(0,nrow(gdata_n_i6)+10)) matlines(gdata_n_i6,col=my_col) title(main=paste(country,"-",unit,": 7. Variation in hospitalization for 10 000 inhabitants",my_last_date)) abline(h=0,col="darkgray") legend("topright",bg="transparent",legend=colnames(gdata_n_i6),col=my_col, text.col = my_col,box.lwd=-1, lty=1, pch=my_pch,ncol=1,cex=0.8) #Reanimation gdata$dtot_n<-ave((ifelse(is.na(gdata$deaths_2_pop),0,gdata$deaths_2_pop)>death_2_pop_threshold & gdata$population>population_threshold),gdata$location,FUN=function(x) cumsum(x)) gdata_n<-gdata[(gdata$dtot_n>0) %in% TRUE,] gdata_n$location<-factor(gdata_n$location) gdata_n_i6<-tapply(10000*gdata_n$reanimation,list(gdata_n$dtot_n,gdata_n$location), mean, na.rm=TRUE) gdata_n_i6<-gdata_n_i6[,vmax$row[vmax$rank<=25]] matplot(gdata_n_i6,pch=my_pch,col=my_col,ylab="Reanimation for 10 000 inhabitants (log scale)", log="y", las = 1,cex.axis=0.8,xlab=label_death_2_pop,xlim = c(0,nrow(gdata_n_i6)+10)) matlines(gdata_n_i6,col=my_col) title(main=paste(country,"-",unit,": 8. Reanimation for 10 000 inhabitants on",my_last_date)) legend("bottomright",bg="transparent",legend=colnames(gdata_n_i6),col=my_col, text.col = my_col,box.lwd=-1, lty=1, pch=my_pch,ncol=1,cex=0.8) #Reanimation variation gdata$reanimation_evol_7<-(rowMeans(cbind(gdata$population*gdata$reanimation_evol, gdata$population*simplelag(gdata$reanimation_evol,gdata$location,mylag = 1,outside =0), gdata$population*simplelag(gdata$reanimation_evol,gdata$location,mylag = 2,outside =0), gdata$population*simplelag(gdata$reanimation_evol,gdata$location,mylag = 3,outside =0), gdata$population*simplelag(gdata$reanimation_evol,gdata$location,mylag = 4,outside =0), gdata$population*simplelag(gdata$reanimation_evol,gdata$location,mylag = 5,outside =0), gdata$population*simplelag(gdata$reanimation_evol,gdata$location,mylag = 6,outside =0),na.rm=TRUE)))/gdata$population gdata$dtot_n<-ave((ifelse(is.na(gdata$deaths_2_pop),0,gdata$deaths_2_pop)>death_2_pop_threshold & gdata$population>population_threshold),gdata$location,FUN=function(x) cumsum(x)) gdata_n<-gdata[(gdata$dtot_n>0) %in% TRUE,] gdata_n$location<-factor(gdata_n$location) gdata_n_i6<-tapply(10000*gdata_n$reanimation_evol_7,list(gdata_n$dtot_n,gdata_n$location), mean, na.rm=TRUE) gdata_n_i6<-gdata_n_i6[,vmax$row[vmax$rank<=25]] matplot(gdata_n_i6,pch=my_pch,col=my_col,ylab="Variation in reanimation for 10 000 inhabitants (7-day moving average)", las = 1,cex.axis=0.8,xlab=label_death_2_pop,xlim = c(0,nrow(gdata_n_i6)+10)) matlines(gdata_n_i6,col=my_col) title(main=paste(country,"-",unit,": 9. Variation in reanimation for 10 000 inhabitants",my_last_date)) abline(h=0,col="darkgray") legend("topright",bg="transparent",legend=colnames(gdata_n_i6),col=my_col, text.col = my_col,box.lwd=-1, lty=1, pch=my_pch,ncol=1,cex=0.8) #Hospitalized for 100 hospital beds gdata_n<-gdata[(gdata$dtot_n>0) %in% TRUE,] gdata_n$location<-factor(gdata_n$location) gdata_n_i6<-tapply(100*gdata_n$hospitalized_per_beds,list(gdata_n$dtot_n,gdata_n$location), mean, na.rm=TRUE) gdata_n_i6<-gdata_n_i6[,vmax$row[vmax$rank<=25]] matplot(gdata_n_i6,pch=my_pch,col=my_col,ylab="Hospitalized for 100 hospital beds (log scale)", log="y", las = 1,cex.axis=0.8,xlab=label_death_2_pop,xlim = c(0,nrow(gdata_n_i6)+10)) matlines(gdata_n_i6,col=my_col) title(main=paste(country,"-",unit,": 10. Hospitalized for 100 hospital beds on",my_last_date)) legend("bottomright",bg="transparent",legend=colnames(gdata_n_i6),col=my_col, text.col = my_col,box.lwd=-1, lty=1, pch=my_pch,ncol=1,cex=0.8) #Reanimation for 100 hospital beds gdata_n<-gdata[(gdata$dtot_n>0) %in% TRUE,] gdata_n$location<-factor(gdata_n$location) gdata_n_i6<-tapply(100*gdata_n$reanimation_per_beds,list(gdata_n$dtot_n,gdata_n$location), mean, na.rm=TRUE) gdata_n_i6<-gdata_n_i6[,vmax$row[vmax$rank<=25]] matplot(gdata_n_i6,pch=my_pch,col=my_col,ylab="Reanimation for 100 hospital beds (log scale)", log="y", las = 1,cex.axis=0.8,xlab=label_death_2_pop,xlim = c(0,nrow(gdata_n_i6)+10)) matlines(gdata_n_i6,col=my_col) title(main=paste(country,"-",unit,": 11. Reanimation for 100 hospital beds on",my_last_date)) legend("bottomright",bg="transparent",legend=colnames(gdata_n_i6),col=my_col, text.col = my_col,box.lwd=-1, lty=1, pch=my_pch,ncol=1,cex=0.8) ######################################################## #UK COVID GRAPHS ######################################################## gdata gdata<-uk country<-"United Kingdom" unit<-"Regions and countries" case_threshold<-uk_case_threshold death_threshold<-uk_death_threshold population_threshold<-uk_population_threshold death_2_pop_threshold<-uk_death_2_pop_threshold cases_2_pop_threshold<-uk_cases_2_pop_threshold label_cases<-paste("Days since number of cases >",case_threshold) label_death<-paste("Days since number of deaths >",death_threshold) label_death_2_pop<-paste("Days since number of deaths for 100,000 inhabitants >",death_2_pop_threshold) label_cases_2_pop<-paste("Days since number of cases for 10,000 inhabitants >",cases_2_pop_threshold) my_last_date<-substr(as.vector(as.data.frame(table(gdata$date))[length(table(gdata$date)),"Var1"]),1,10) gdata$new_cases_7<-rowMeans(data.frame(gdata$new_cases, simplelag(gdata$new_cases,gdata$location,mylag = 1,outside =0), simplelag(gdata$new_cases,gdata$location,mylag = 2,outside =0), simplelag(gdata$new_cases,gdata$location,mylag = 3,outside =0), simplelag(gdata$new_cases,gdata$location,mylag = 4,outside =0), simplelag(gdata$new_cases,gdata$location,mylag = 5,outside =0), simplelag(gdata$new_cases,gdata$location,mylag = 6,outside =0)),na.rm=TRUE) gdata$new_deaths_7<-rowMeans(cbind(gdata$new_deaths, simplelag(gdata$new_deaths,gdata$location,mylag = 1,outside =0), simplelag(gdata$new_deaths,gdata$location,mylag = 2,outside =0), simplelag(gdata$new_deaths,gdata$location,mylag = 3,outside =0), simplelag(gdata$new_deaths,gdata$location,mylag = 4,outside =0), simplelag(gdata$new_deaths,gdata$location,mylag = 5,outside =0), simplelag(gdata$new_deaths,gdata$location,mylag = 6,outside =0)),na.rm = TRUE) ##TOTAL CASES 2 POP SINCE TOTAL CASES ABOVE THRESHOLD gdata$dtot_n<-ave((ifelse(is.na(gdata$cases_2_pop),0,gdata$cases_2_pop)>cases_2_pop_threshold & gdata$population>population_threshold),gdata$location,FUN=function(x) cumsum(x)) gdata_n<-gdata[(gdata$dtot_n>0) %in% TRUE,] gdata_n$location<-factor(gdata_n$location) gdata_n_i6<-tapply(gdata_n$cases_2_pop,list(gdata_n$dtot_n,gdata_n$location), mean, na.rm=TRUE) vmax<-data.frame(apply(as.data.frame(gdata_n_i6),2,function(x) max(x,na.rm=TRUE))) colnames(vmax)<-"max" vmax$rank<-rank(-vmax$max) vmax$location<-row.names(vmax) vmax$row<-cumsum(1-is.na(row.names(vmax))) gdata_n_i6<-gdata_n_i6[,vmax$row[vmax$rank<=25]] matplot(gdata_n_i6,pch=my_pch,col=my_col,ylab="Cases for 10,000 inhabitants (log scale)", xlim = c(0,nrow(gdata_n_i6)+10), log="y", las = 1,cex.axis=0.8,xlab=label_cases_2_pop) matlines(gdata_n_i6,col=my_col) title(main=paste(country,"-",unit,": 1. Cases for 10,000 inhabitants on",my_last_date)) legend("bottomright",bg="transparent",legend=colnames(gdata_n_i6),col=my_col, text.col = my_col,box.lwd=-1, lty=1, pch=my_pch,ncol=1,cex=0.8) #NEW CASES 2 POP SINCE TOTAL CASES ABOVE THRESHOLD gdata$new_cases_2_pop<-10000*gdata$new_cases_7/gdata$population gdata$dtot_n<-ave((ifelse(is.na(gdata$cases_2_pop),0,gdata$cases_2_pop)>cases_2_pop_threshold & gdata$population>population_threshold),gdata$location,FUN=function(x) cumsum(x)) gdata_n<-gdata[(gdata$dtot_n>0) %in% TRUE,] gdata_n$location<-factor(gdata_n$location) gdata_n_i6<-tapply(gdata_n$new_cases_2_pop,list(gdata_n$dtot_n,gdata_n$location), mean, na.rm=TRUE) gdata_n_i6<-gdata_n_i6[,vmax$row[vmax$rank<=25]] matplot(gdata_n_i6,pch=my_pch,col=my_col,ylab="New cases for 10,000 inhabitants (7-day moving average - log scale)", log="y", las = 1,cex.axis=0.8,xlab=label_cases_2_pop,xlim = c(0,nrow(gdata_n_i6)+10)) matlines(gdata_n_i6,col=my_col) title(main=paste(country,"-",unit,": 2. New cases for 10,000 inhabitants on",my_last_date)) legend("bottomright",bg="transparent",legend=colnames(gdata_n_i6),col=my_col, text.col = my_col,box.lwd=-1, lty=1, pch=my_pch,ncol=1,cex=0.8) #TOTAL DEATHS 2 POP SINCE TOTAL DEATHS ABOVE THRESHOLD gdata$dtot_n<-ave((ifelse(is.na(gdata$deaths_2_pop),0,gdata$deaths_2_pop)>death_2_pop_threshold & gdata$population>population_threshold),gdata$location,FUN=function(x) cumsum(x)) gdata_n<-gdata[(gdata$dtot_n>0) %in% TRUE,] gdata_n$location<-factor(gdata_n$location) gdata_n_i6<-tapply(gdata_n$deaths_2_pop,list(gdata_n$dtot_n,gdata_n$location), mean, na.rm=TRUE) vmax<-data.frame(apply(as.data.frame(gdata_n_i6),2,function(x) max(x,na.rm=TRUE))) colnames(vmax)<-"max" vmax$rank<-rank(-vmax$max) vmax$location<-row.names(vmax) vmax$row<-cumsum(1-is.na(row.names(vmax))) dmax<-vmax gdata_n_i6<-gdata_n_i6[,vmax$row[vmax$rank<=25]] matplot(gdata_n_i6,pch=my_pch,col=my_col,ylab="Deaths for 100,000 inhabitants (log scale)", log="y", las = 1,cex.axis=0.8,xlab=label_death_2_pop,xlim = c(0,nrow(gdata_n_i6)+10)) matlines(gdata_n_i6,col=my_col) title(main=paste(country,"-",unit,": 3. Deaths for 100,000 inhabitants on",my_last_date)) legend("bottomright",bg="transparent",legend=colnames(gdata_n_i6),col=my_col, text.col = my_col,box.lwd=-1, lty=1, pch=my_pch,ncol=1,cex=0.8) #New DEATHS 2 POP SINCE TOTAL DEATHS ABOVE THRESHOLD gdata$new_deaths_2_pop<-100000*gdata$new_deaths_7/gdata$population gdata$dtot_n<-ave((ifelse(is.na(gdata$deaths_2_pop),0,gdata$deaths_2_pop)>death_2_pop_threshold & gdata$population>population_threshold),gdata$location,FUN=function(x) cumsum(x)) gdata_n<-gdata[(gdata$dtot_n>0) %in% TRUE,] gdata_n$location<-factor(gdata_n$location) gdata_n_i6<-tapply(gdata_n$new_deaths_2_pop,list(gdata_n$dtot_n,gdata_n$location), mean, na.rm=TRUE) gdata_n_i6<-gdata_n_i6[,vmax$row[vmax$rank<=25]] matplot(gdata_n_i6,pch=my_pch,col=my_col,ylab="New deaths for 100,000 inhabitants (7-day moving average - log scale)", log="y", las = 1,cex.axis=0.8,xlab=label_death_2_pop,xlim = c(0,nrow(gdata_n_i6)+10)) matlines(gdata_n_i6,col=my_col) title(main=paste(country,"-",unit,": 4. New deaths for 100,000 inhabitants on",my_last_date)) legend("bottomright",bg="transparent",legend=colnames(gdata_n_i6),col=my_col, text.col = my_col,box.lwd=-1, lty=1, pch=my_pch,ncol=1,cex=0.8) #LETALITY DEATHS 2 CASES SINCE TOTAL DEATHS ABOVE THRESHOLD gdata$deaths_2_cases<-100*gdata$total_deaths/gdata$total_cases gdata$dtot_n<-ave((ifelse(is.na(gdata$deaths_2_pop),0,gdata$deaths_2_pop)>death_2_pop_threshold & gdata$population>population_threshold),gdata$location,FUN=function(x) cumsum(x)) gdata_n<-gdata[(gdata$dtot_n>0) %in% TRUE,] gdata_n$location<-factor(gdata_n$location) gdata_n_i6<-tapply(gdata_n$deaths_2_cases,list(gdata_n$dtot_n,gdata_n$location), mean, na.rm=TRUE) gdata_n_i6<-gdata_n_i6[,vmax$row[vmax$rank<=25]] matplot(gdata_n_i6,pch=my_pch,col=my_col,ylab="Deaths for 100 cases (log scale)", log="y", las = 1,cex.axis=0.8,xlab=label_death_2_pop,xlim = c(0,nrow(gdata_n_i6)+10)) matlines(gdata_n_i6,col=my_col) title(main=paste(country,"-",unit,": 5. Deaths for 100 cases on",my_last_date)) legend("bottomright",bg="transparent",legend=colnames(gdata_n_i6),col=my_col, text.col = my_col,box.lwd=-1, lty=1, pch=my_pch,ncol=1,cex=0.8) ######################################################## #USA COVID GRAPHS ######################################################## gdata<-usa country<-"USA" unit<-"Top 25 States" case_threshold<-usa_case_threshold death_threshold<-usa_death_threshold population_threshold<-usa_population_threshold death_2_pop_threshold<-usa_death_2_pop_threshold cases_2_pop_threshold<-usa_cases_2_pop_threshold label_cases<-paste("Days since number of cases >",case_threshold) label_death<-paste("Days since number of deaths >",death_threshold) label_death_2_pop<-paste("Days since number of deaths for 100,000 inhabitants >",death_2_pop_threshold) label_cases_2_pop<-paste("Days since number of cases for 10,000 inhabitants >",cases_2_pop_threshold) my_last_date<-substr(as.vector(as.data.frame(table(gdata$date))[length(table(gdata$date)),"Var1"]),1,10) gdata$new_cases_7<-rowMeans(data.frame(gdata$new_cases, simplelag(gdata$new_cases,gdata$location,mylag = 1,outside =0), simplelag(gdata$new_cases,gdata$location,mylag = 2,outside =0), simplelag(gdata$new_cases,gdata$location,mylag = 3,outside =0), simplelag(gdata$new_cases,gdata$location,mylag = 4,outside =0), simplelag(gdata$new_cases,gdata$location,mylag = 5,outside =0), simplelag(gdata$new_cases,gdata$location,mylag = 6,outside =0)),na.rm=TRUE) gdata$new_deaths_7<-rowMeans(cbind(gdata$new_deaths, simplelag(gdata$new_deaths,gdata$location,mylag = 1,outside =0), simplelag(gdata$new_deaths,gdata$location,mylag = 2,outside =0), simplelag(gdata$new_deaths,gdata$location,mylag = 3,outside =0), simplelag(gdata$new_deaths,gdata$location,mylag = 4,outside =0), simplelag(gdata$new_deaths,gdata$location,mylag = 5,outside =0), simplelag(gdata$new_deaths,gdata$location,mylag = 6,outside =0)),na.rm = TRUE) ##TOTAL CASES 2 POP SINCE TOTAL CASES ABOVE THRESHOLD gdata$dtot_n<-ave((ifelse(is.na(gdata$cases_2_pop),0,gdata$cases_2_pop)>cases_2_pop_threshold & gdata$population>population_threshold),gdata$location,FUN=function(x) cumsum(x)) gdata_n<-gdata[(gdata$dtot_n>0) %in% TRUE,] gdata_n$location<-factor(gdata_n$location) gdata_n_i6<-tapply(gdata_n$cases_2_pop,list(gdata_n$dtot_n,gdata_n$location), mean, na.rm=TRUE) vmax<-data.frame(apply(as.data.frame(gdata_n_i6),2,function(x) max(x,na.rm=TRUE))) colnames(vmax)<-"max" vmax$rank<-rank(-vmax$max) vmax$location<-row.names(vmax) vmax$row<-cumsum(1-is.na(row.names(vmax))) gdata_n_i6<-gdata_n_i6[,vmax$row[vmax$rank<=25]] matplot(gdata_n_i6,pch=my_pch,col=my_col,ylab="Cases for 10,000 inhabitants (log scale)", xlim = c(0,nrow(gdata_n_i6)+10), log="y", las = 1,cex.axis=0.8,xlab=label_cases_2_pop) matlines(gdata_n_i6,col=my_col) title(main=paste(country,"-",unit,": 1. Cases for 10,000 inhabitants on",my_last_date)) legend("bottomright",bg="transparent",legend=colnames(gdata_n_i6),col=my_col, text.col = my_col,box.lwd=-1, lty=1, pch=my_pch,ncol=1,cex=0.8) #NEW CASES 2 POP SINCE TOTAL CASES ABOVE THRESHOLD gdata$new_cases_2_pop<-10000*gdata$new_cases_7/gdata$population gdata$dtot_n<-ave((ifelse(is.na(gdata$cases_2_pop),0,gdata$cases_2_pop)>cases_2_pop_threshold & gdata$population>population_threshold),gdata$location,FUN=function(x) cumsum(x)) gdata_n<-gdata[(gdata$dtot_n>0) %in% TRUE,] gdata_n$location<-factor(gdata_n$location) gdata_n_i6<-tapply(gdata_n$new_cases_2_pop,list(gdata_n$dtot_n,gdata_n$location), mean, na.rm=TRUE) gdata_n_i6<-gdata_n_i6[,vmax$row[vmax$rank<=25]] matplot(gdata_n_i6,pch=my_pch,col=my_col,ylab="New cases for 10,000 inhabitants (7-day moving average - log scale)", log="y", las = 1,cex.axis=0.8,xlab=label_cases_2_pop,xlim = c(0,nrow(gdata_n_i6)+10)) matlines(gdata_n_i6,col=my_col) title(main=paste(country,"-",unit,": 2. New cases for 10,000 inhabitants on",my_last_date)) legend("bottomright",bg="transparent",legend=colnames(gdata_n_i6),col=my_col, text.col = my_col,box.lwd=-1, lty=1, pch=my_pch,ncol=1,cex=0.8) #TOTAL DEATHS 2 POP SINCE TOTAL DEATHS ABOVE THRESHOLD gdata$dtot_n<-ave((ifelse(is.na(gdata$deaths_2_pop),0,gdata$deaths_2_pop)>death_2_pop_threshold & gdata$population>population_threshold),gdata$location,FUN=function(x) cumsum(x)) gdata_n<-gdata[(gdata$dtot_n>0) %in% TRUE,] gdata_n$location<-factor(gdata_n$location) gdata_n_i6<-tapply(gdata_n$deaths_2_pop,list(gdata_n$dtot_n,gdata_n$location), mean, na.rm=TRUE) vmax<-data.frame(apply(as.data.frame(gdata_n_i6),2,function(x) max(x,na.rm=TRUE))) colnames(vmax)<-"max" vmax$rank<-rank(-vmax$max) vmax$location<-row.names(vmax) vmax$row<-cumsum(1-is.na(row.names(vmax))) dmax<-vmax gdata_n_i6<-gdata_n_i6[,vmax$row[vmax$rank<=25]] matplot(gdata_n_i6,pch=my_pch,col=my_col,ylab="Deaths for 100,000 inhabitants (log scale)", log="y", las = 1,cex.axis=0.8,xlab=label_death_2_pop,xlim = c(0,nrow(gdata_n_i6)+10)) matlines(gdata_n_i6,col=my_col) title(main=paste(country,"-",unit,": 3. Deaths for 100,000 inhabitants on",my_last_date)) legend("bottomright",bg="transparent",legend=colnames(gdata_n_i6),col=my_col, text.col = my_col,box.lwd=-1, lty=1, pch=my_pch,ncol=1,cex=0.8) #New DEATHS 2 POP SINCE TOTAL DEATHS ABOVE THRESHOLD gdata$new_deaths_2_pop<-100000*gdata$new_deaths_7/gdata$population gdata$dtot_n<-ave((ifelse(is.na(gdata$deaths_2_pop),0,gdata$deaths_2_pop)>death_2_pop_threshold & gdata$population>population_threshold),gdata$location,FUN=function(x) cumsum(x)) gdata_n<-gdata[(gdata$dtot_n>0) %in% TRUE,] gdata_n$location<-factor(gdata_n$location) gdata_n_i6<-tapply(gdata_n$new_deaths_2_pop,list(gdata_n$dtot_n,gdata_n$location), mean, na.rm=TRUE) gdata_n_i6<-gdata_n_i6[,vmax$row[vmax$rank<=25]] matplot(gdata_n_i6,pch=my_pch,col=my_col,ylab="New deaths for 100,000 inhabitants (7-day moving average - log scale)", log="y", las = 1,cex.axis=0.8,xlab=label_death_2_pop,xlim = c(0,nrow(gdata_n_i6)+10)) matlines(gdata_n_i6,col=my_col) title(main=paste(country,"-",unit,": 4. New deaths for 100,000 inhabitants on",my_last_date)) legend("bottomright",bg="transparent",legend=colnames(gdata_n_i6),col=my_col, text.col = my_col,box.lwd=-1, lty=1, pch=my_pch,ncol=1,cex=0.8) #LETALITY DEATHS 2 CASES SINCE TOTAL DEATHS ABOVE THRESHOLD gdata$deaths_2_cases<-100*gdata$total_deaths/gdata$total_cases gdata$dtot_n<-ave((ifelse(is.na(gdata$deaths_2_pop),0,gdata$deaths_2_pop)>death_2_pop_threshold & gdata$population>population_threshold),gdata$location,FUN=function(x) cumsum(x)) gdata_n<-gdata[(gdata$dtot_n>0) %in% TRUE,] gdata_n$location<-factor(gdata_n$location) gdata_n_i6<-tapply(gdata_n$deaths_2_cases,list(gdata_n$dtot_n,gdata_n$location), mean, na.rm=TRUE) gdata_n_i6<-gdata_n_i6[,vmax$row[vmax$rank<=25]] matplot(gdata_n_i6,pch=my_pch,col=my_col,ylab="Deaths for 100 cases (log scale)", log="y", las = 1,cex.axis=0.8,xlab=label_death_2_pop,xlim = c(0,nrow(gdata_n_i6)+10)) matlines(gdata_n_i6,col=my_col) title(main=paste(country,"-",unit,": 5. Deaths for 100 cases on",my_last_date)) legend("bottomright",bg="transparent",legend=colnames(gdata_n_i6),col=my_col, text.col = my_col,box.lwd=-1, lty=1, pch=my_pch,ncol=1,cex=0.8) #pdf(file="covid19-germany.pdf",paper="A4r",width=10,height=7,family="Bookman") ######################################################## #German COVID GRAPHS ######################################################## #German Lander gdata<-germany_land country<-"Germany" unit<-"Lander" case_threshold<-germany_case_threshold death_threshold<-germany_death_threshold population_threshold<-germany_population_threshold death_2_pop_threshold<-germany_death_2_pop_threshold cases_2_pop_threshold<-germany_cases_2_pop_threshold label_cases<-paste("Days since number of cases >",case_threshold) label_death<-paste("Days since number of deaths >",death_threshold) label_death_2_pop<-paste("Days since number of deaths for 100,000 inhabitants >",death_2_pop_threshold) label_cases_2_pop<-paste("Days since number of cases for 10,000 inhabitants >",cases_2_pop_threshold) my_last_date<-substr(as.vector(as.data.frame(table(gdata$date))[length(table(gdata$date)),"Var1"]),1,10) gdata$new_cases_7<-rowMeans(data.frame(gdata$new_cases, simplelag(gdata$new_cases,gdata$location,mylag = 1,outside =0), simplelag(gdata$new_cases,gdata$location,mylag = 2,outside =0), simplelag(gdata$new_cases,gdata$location,mylag = 3,outside =0), simplelag(gdata$new_cases,gdata$location,mylag = 4,outside =0), simplelag(gdata$new_cases,gdata$location,mylag = 5,outside =0), simplelag(gdata$new_cases,gdata$location,mylag = 6,outside =0)),na.rm=TRUE) gdata$new_deaths_7<-rowMeans(cbind(gdata$new_deaths, simplelag(gdata$new_deaths,gdata$location,mylag = 1,outside =0), simplelag(gdata$new_deaths,gdata$location,mylag = 2,outside =0), simplelag(gdata$new_deaths,gdata$location,mylag = 3,outside =0), simplelag(gdata$new_deaths,gdata$location,mylag = 4,outside =0), simplelag(gdata$new_deaths,gdata$location,mylag = 5,outside =0), simplelag(gdata$new_deaths,gdata$location,mylag = 6,outside =0)),na.rm = TRUE) ##TOTAL CASES 2 POP SINCE TOTAL CASES ABOVE THRESHOLD gdata$dtot_n<-ave((ifelse(is.na(gdata$cases_2_pop),0,gdata$cases_2_pop)>cases_2_pop_threshold & gdata$population>population_threshold),gdata$location,FUN=function(x) cumsum(x)) gdata_n<-gdata[(gdata$dtot_n>0) %in% TRUE,] gdata_n$location<-factor(gdata_n$location) gdata_n_i6<-tapply(gdata_n$cases_2_pop,list(gdata_n$dtot_n,gdata_n$location), mean, na.rm=TRUE) vmax<-data.frame(apply(as.data.frame(gdata_n_i6),2,function(x) max(x,na.rm=TRUE))) colnames(vmax)<-"max" vmax$rank<-rank(-vmax$max) vmax$location<-row.names(vmax) vmax$row<-cumsum(1-is.na(row.names(vmax))) gdata_n_i6<-gdata_n_i6[,vmax$row[vmax$rank<=25]] matplot(gdata_n_i6,pch=my_pch,col=my_col,ylab="Cases for 10,000 inhabitants (log scale)", xlim = c(0,nrow(gdata_n_i6)+10), log="y", las = 1,cex.axis=0.8,xlab=label_cases_2_pop) matlines(gdata_n_i6,col=my_col) title(main=paste(country,"-",unit,": 1. Cases for 10,000 inhabitants on",my_last_date)) legend("bottomright",bg="transparent",legend=colnames(gdata_n_i6),col=my_col, text.col = my_col,box.lwd=-1, lty=1, pch=my_pch,ncol=1,cex=0.8) #NEW CASES 2 POP SINCE TOTAL CASES ABOVE THRESHOLD gdata$new_cases_2_pop<-10000*gdata$new_cases_7/gdata$population gdata$dtot_n<-ave((ifelse(is.na(gdata$cases_2_pop),0,gdata$cases_2_pop)>cases_2_pop_threshold & gdata$population>population_threshold),gdata$location,FUN=function(x) cumsum(x)) gdata_n<-gdata[(gdata$dtot_n>0) %in% TRUE,] gdata_n$location<-factor(gdata_n$location) gdata_n_i6<-tapply(gdata_n$new_cases_2_pop,list(gdata_n$dtot_n,gdata_n$location), mean, na.rm=TRUE) gdata_n_i6<-gdata_n_i6[,vmax$row[vmax$rank<=25]] # gdata_n_spe<-gdata_n_i6[,c("LK Ennepe-Ruhr-Kreis","SK Wuppertal")] matplot(gdata_n_i6,pch=my_pch,col=my_col,ylab="New cases for 10,000 inhabitants (7-day moving average - log scale)", log="y", las = 1,cex.axis=0.8,xlab=label_cases_2_pop,xlim = c(0,nrow(gdata_n_i6)+10)) matlines(gdata_n_i6,col=my_col) title(main=paste(country,"-",unit,": 2. New cases for 10,000 inhabitants on",my_last_date)) legend("bottomright",bg="transparent",legend=colnames(gdata_n_i6),col=my_col, text.col = my_col,box.lwd=-1, lty=1, pch=my_pch,ncol=1,cex=0.8) #TOTAL DEATHS 2 POP SINCE TOTAL DEATHS ABOVE THRESHOLD gdata$dtot_n<-ave((ifelse(is.na(gdata$deaths_2_pop),0,gdata$deaths_2_pop)>death_2_pop_threshold & gdata$population>population_threshold),gdata$location,FUN=function(x) cumsum(x)) gdata_n<-gdata[(gdata$dtot_n>0) %in% TRUE,] gdata_n$location<-factor(gdata_n$location) gdata_n_i6<-tapply(gdata_n$deaths_2_pop,list(gdata_n$dtot_n,gdata_n$location), mean, na.rm=TRUE) vmax<-data.frame(apply(as.data.frame(gdata_n_i6),2,function(x) max(x,na.rm=TRUE))) colnames(vmax)<-"max" vmax$rank<-rank(-vmax$max) vmax$location<-row.names(vmax) vmax$row<-cumsum(1-is.na(row.names(vmax))) dmax<-vmax gdata_n_i6<-gdata_n_i6[,vmax$row[vmax$rank<=25]] matplot(gdata_n_i6,pch=my_pch,col=my_col,ylab="Deaths for 100,000 inhabitants (log scale)", log="y", las = 1,cex.axis=0.8,xlab=label_death_2_pop,xlim = c(0,nrow(gdata_n_i6)+10)) matlines(gdata_n_i6,col=my_col) title(main=paste(country,"-",unit,": 3. Deaths for 100,000 inhabitants on",my_last_date)) legend("bottomright",bg="transparent",legend=colnames(gdata_n_i6),col=my_col, text.col = my_col,box.lwd=-1, lty=1, pch=my_pch,ncol=1,cex=0.8) #New DEATHS 2 POP SINCE TOTAL DEATHS ABOVE THRESHOLD gdata$new_deaths_2_pop<-100000*gdata$new_deaths_7/gdata$population gdata$dtot_n<-ave((ifelse(is.na(gdata$deaths_2_pop),0,gdata$deaths_2_pop)>death_2_pop_threshold & gdata$population>population_threshold),gdata$location,FUN=function(x) cumsum(x)) gdata_n<-gdata[(gdata$dtot_n>0) %in% TRUE,] gdata_n$location<-factor(gdata_n$location) gdata_n_i6<-tapply(gdata_n$new_deaths_2_pop,list(gdata_n$dtot_n,gdata_n$location), mean, na.rm=TRUE) gdata_n_i6<-gdata_n_i6[,vmax$row[vmax$rank<=25]] matplot(gdata_n_i6,pch=my_pch,col=my_col,ylab="New deaths for 100,000 inhabitants (7-day moving average - log scale)", log="y", las = 1,cex.axis=0.8,xlab=label_death_2_pop,xlim = c(0,nrow(gdata_n_i6)+10)) matlines(gdata_n_i6,col=my_col) title(main=paste(country,"-",unit,": 4. New deaths for 100,000 inhabitants on",my_last_date)) legend("bottomright",bg="transparent",legend=colnames(gdata_n_i6),col=my_col, text.col = my_col,box.lwd=-1, lty=1, pch=my_pch,ncol=1,cex=0.8) #LETALITY DEATHS 2 CASES SINCE TOTAL DEATHS ABOVE THRESHOLD gdata$deaths_2_cases<-100*gdata$total_deaths/gdata$total_cases gdata$dtot_n<-ave((ifelse(is.na(gdata$deaths_2_pop),0,gdata$deaths_2_pop)>death_2_pop_threshold & gdata$population>population_threshold),gdata$location,FUN=function(x) cumsum(x)) gdata_n<-gdata[(gdata$dtot_n>0) %in% TRUE,] gdata_n$location<-factor(gdata_n$location) gdata_n_i6<-tapply(gdata_n$deaths_2_cases,list(gdata_n$dtot_n,gdata_n$location), mean, na.rm=TRUE) gdata_n_i6<-gdata_n_i6[,vmax$row[vmax$rank<=25]] matplot(gdata_n_i6,pch=my_pch,col=my_col,ylab="Deaths for 100 cases (log scale)", log="y", las = 1,cex.axis=0.8,xlab=label_death_2_pop,xlim = c(0,nrow(gdata_n_i6)+10)) matlines(gdata_n_i6,col=my_col) title(main=paste(country,"-",unit,": 5. Deaths for 100 cases on",my_last_date)) legend("bottomright",bg="transparent",legend=colnames(gdata_n_i6),col=my_col, text.col = my_col,box.lwd=-1, lty=1, pch=my_pch,ncol=1,cex=0.8) #Germany Detailed regions gdata<-germany_reg country<-"Germany" unit<-"Top 25 Landkreis" case_threshold<-germany_det_case_threshold death_threshold<-germany_det_death_threshold label_cases<-paste("Days since number of cases >",case_threshold) label_death<-paste("Days since number of deaths >",death_threshold) my_last_date<-substr(as.vector(as.data.frame(table(gdata$date))[length(table(gdata$date)),"Var1"]),1,10) gdata$new_cases_7<-rowMeans(data.frame(gdata$new_cases, simplelag(gdata$new_cases,gdata$location,mylag = 1,outside =0), simplelag(gdata$new_cases,gdata$location,mylag = 2,outside =0), simplelag(gdata$new_cases,gdata$location,mylag = 3,outside =0), simplelag(gdata$new_cases,gdata$location,mylag = 4,outside =0), simplelag(gdata$new_cases,gdata$location,mylag = 5,outside =0), simplelag(gdata$new_cases,gdata$location,mylag = 6,outside =0)),na.rm=TRUE) gdata$new_deaths_7<-rowMeans(cbind(gdata$new_deaths, simplelag(gdata$new_deaths,gdata$location,mylag = 1,outside =0), simplelag(gdata$new_deaths,gdata$location,mylag = 2,outside =0), simplelag(gdata$new_deaths,gdata$location,mylag = 3,outside =0), simplelag(gdata$new_deaths,gdata$location,mylag = 4,outside =0), simplelag(gdata$new_deaths,gdata$location,mylag = 5,outside =0), simplelag(gdata$new_deaths,gdata$location,mylag = 6,outside =0)),na.rm = TRUE) ##TOTAL CASES 2 POP SINCE TOTAL CASES ABOVE THRESHOLD gdata$dtot_n<-ave((ifelse(is.na(gdata$cases_2_pop),0,gdata$cases_2_pop)>cases_2_pop_threshold & gdata$population>population_threshold),gdata$location,FUN=function(x) cumsum(x)) gdata_n<-gdata[(gdata$dtot_n>0) %in% TRUE,] gdata_n$location<-factor(gdata_n$location) gdata_n_i6<-tapply(gdata_n$cases_2_pop,list(gdata_n$dtot_n,gdata_n$location), mean, na.rm=TRUE) vmax<-data.frame(apply(as.data.frame(gdata_n_i6),2,function(x) max(x,na.rm=TRUE))) colnames(vmax)<-"max" vmax$rank<-rank(-vmax$max) vmax$location<-row.names(vmax) vmax$row<-cumsum(1-is.na(row.names(vmax))) # gdata_n_spe<-gdata_n_i6[,c("LK Ennepe-Ruhr-Kreis","SK Wuppertal")] gdata_n_i6<-gdata_n_i6[,vmax$row[vmax$rank<=25]] # gdata_n_i6<-cbind(gdata_n_i6,gdata_n_spe) matplot(gdata_n_i6,pch=my_pch,col=my_col,ylab="Cases for 10,000 inhabitants (log scale)", xlim = c(0,nrow(gdata_n_i6)+10), log="y", las = 1,cex.axis=0.8,xlab=label_cases_2_pop) matlines(gdata_n_i6,col=my_col) title(main=paste(country,"-",unit,": 1. Cases for 10,000 inhabitants on",my_last_date)) legend("bottomright",bg="transparent",legend=colnames(gdata_n_i6),col=my_col, text.col = my_col,box.lwd=-1, lty=1, pch=my_pch,ncol=1,cex=0.8) #NEW CASES 2 POP SINCE TOTAL CASES ABOVE THRESHOLD gdata$new_cases_2_pop<-10000*gdata$new_cases_7/gdata$population gdata$dtot_n<-ave((ifelse(is.na(gdata$cases_2_pop),0,gdata$cases_2_pop)>cases_2_pop_threshold & gdata$population>population_threshold),gdata$location,FUN=function(x) cumsum(x)) gdata_n<-gdata[(gdata$dtot_n>0) %in% TRUE,] gdata_n$location<-factor(gdata_n$location) gdata_n_i6<-tapply(gdata_n$new_cases_2_pop,list(gdata_n$dtot_n,gdata_n$location), mean, na.rm=TRUE) # gdata_n_spe<-gdata_n_i6[,c("LK Ennepe-Ruhr-Kreis","SK Wuppertal")] gdata_n_i6<-gdata_n_i6[,vmax$row[vmax$rank<=25]] # gdata_n_i6<-cbind(gdata_n_i6,gdata_n_spe) matplot(gdata_n_i6,pch=my_pch,col=my_col,ylab="New cases for 10,000 inhabitants (7-day moving average - log scale)", log="y", las = 1,cex.axis=0.8,xlab=label_cases_2_pop,xlim = c(0,nrow(gdata_n_i6)+10)) matlines(gdata_n_i6,col=my_col) title(main=paste(country,"-",unit,": 2. New cases for 10,000 inhabitants on",my_last_date)) legend("bottomright",bg="transparent",legend=colnames(gdata_n_i6),col=my_col, text.col = my_col,box.lwd=-1, lty=1, pch=my_pch,ncol=1,cex=0.8) #TOTAL DEATHS 2 POP SINCE TOTAL DEATHS ABOVE THRESHOLD gdata$dtot_n<-ave((ifelse(is.na(gdata$deaths_2_pop),0,gdata$deaths_2_pop)>death_2_pop_threshold & gdata$population>population_threshold),gdata$location,FUN=function(x) cumsum(x)) gdata_n<-gdata[(gdata$dtot_n>0) %in% TRUE,] gdata_n$location<-factor(gdata_n$location) gdata_n_i6<-tapply(gdata_n$deaths_2_pop,list(gdata_n$dtot_n,gdata_n$location), mean, na.rm=TRUE) vmax<-data.frame(apply(as.data.frame(gdata_n_i6),2,function(x) max(x,na.rm=TRUE))) colnames(vmax)<-"max" vmax$rank<-rank(-vmax$max) vmax$location<-row.names(vmax) vmax$row<-cumsum(1-is.na(row.names(vmax))) dmax<-vmax # gdata_n_spe<-gdata_n_i6[,c("LK Ennepe-Ruhr-Kreis","SK Wuppertal")] gdata_n_i6<-gdata_n_i6[,vmax$row[vmax$rank<=25]] # gdata_n_i6<-cbind(gdata_n_i6,gdata_n_spe) matplot(gdata_n_i6,pch=my_pch,col=my_col,ylab="Deaths for 100,000 inhabitants (log scale)", log="y", las = 1,cex.axis=0.8,xlab=label_death_2_pop,xlim = c(0,nrow(gdata_n_i6)+10)) matlines(gdata_n_i6,col=my_col) title(main=paste(country,"-",unit,": 3. Deaths for 100,000 inhabitants on",my_last_date)) legend("bottomright",bg="transparent",legend=colnames(gdata_n_i6),col=my_col, text.col = my_col,box.lwd=-1, lty=1, pch=my_pch,ncol=1,cex=0.8) #New DEATHS 2 POP SINCE TOTAL DEATHS ABOVE THRESHOLD gdata$new_deaths_2_pop<-100000*gdata$new_deaths_7/gdata$population gdata$dtot_n<-ave((ifelse(is.na(gdata$deaths_2_pop),0,gdata$deaths_2_pop)>death_2_pop_threshold & gdata$population>population_threshold),gdata$location,FUN=function(x) cumsum(x)) gdata_n<-gdata[(gdata$dtot_n>0) %in% TRUE,] gdata_n$location<-factor(gdata_n$location) gdata_n_i6<-tapply(gdata_n$new_deaths_2_pop,list(gdata_n$dtot_n,gdata_n$location), mean, na.rm=TRUE) #colnames(gdata_n_i6) # gdata_n_spe<-gdata_n_i6[,c("LK Ennepe-Ruhr-Kreis","SK Wuppertal")] gdata_n_i6<-gdata_n_i6[,vmax$row[vmax$rank<=25]] # gdata_n_i6<-cbind(gdata_n_i6,gdata_n_spe) matplot(gdata_n_i6,pch=my_pch,col=my_col,ylab="New deaths for 100,000 inhabitants (7-day moving average - log scale)", log="y", las = 1,cex.axis=0.8,xlab=label_death_2_pop,xlim = c(0,nrow(gdata_n_i6)+10)) matlines(gdata_n_i6,col=my_col) title(main=paste(country,"-",unit,": 4. New deaths for 100,000 inhabitants on",my_last_date)) legend("bottomright",bg="transparent",legend=colnames(gdata_n_i6),col=my_col, text.col = my_col,box.lwd=-1, lty=1, pch=my_pch,ncol=1,cex=0.8) #LETALITY DEATHS 2 CASES SINCE TOTAL DEATHS ABOVE THRESHOLD gdata$deaths_2_cases<-100*gdata$total_deaths/gdata$total_cases gdata$dtot_n<-ave((ifelse(is.na(gdata$deaths_2_pop),0,gdata$deaths_2_pop)>death_2_pop_threshold & gdata$population>population_threshold),gdata$location,FUN=function(x) cumsum(x)) gdata_n<-gdata[(gdata$dtot_n>0) %in% TRUE,] gdata_n$location<-factor(gdata_n$location) gdata_n_i6<-tapply(gdata_n$deaths_2_cases,list(gdata_n$dtot_n,gdata_n$location), mean, na.rm=TRUE) # gdata_n_spe<-gdata_n_i6[,c("LK Ennepe-Ruhr-Kreis","SK Wuppertal")] gdata_n_i6<-gdata_n_i6[,vmax$row[vmax$rank<=25]] # gdata_n_i6<-cbind(gdata_n_i6,gdata_n_spe) matplot(gdata_n_i6,pch=my_pch,col=my_col,ylab="Deaths for 100 cases (log scale)", log="y", las = 1,cex.axis=0.8,xlab=label_death_2_pop,xlim = c(0,nrow(gdata_n_i6)+10)) matlines(gdata_n_i6,col=my_col) title(main=paste(country,"-",unit,": 5. Deaths for 100 cases on",my_last_date)) legend("bottomright",bg="transparent",legend=colnames(gdata_n_i6),col=my_col, text.col = my_col,box.lwd=-1, lty=1, pch=my_pch,ncol=1,cex=0.8) dev.off()