#setwd(path)
setwd(dirname(rstudioapi::getActiveDocumentContext()$path))
#clear the environment
rm(list=ls())

# install and load the relevant packages 
# packages used
listofpackages <- c("ellipse","reshape2","ggplot2","dygraphs", "dplyr","forecast", "aod","readr","xlsx")

for (j in listofpackages){
  if(sum(installed.packages()[, 1] == j) == 0) {
    install.packages(j)
  }
  library(j, character.only = T)
}


urlfile="https://raw.githubusercontent.com/pcm-dpc/COVID-19/master/dati-regioni/dpc-covid19-ita-regioni.csv"

COVID_all<-read_csv(url(urlfile))
LOMBARDIA=subset(COVID_all,denominazione_regione=="Lombardia",select=c(1:1,4:4,7:20))
VENETO=subset(COVID_all,denominazione_regione=="Veneto",select=c(1:1,4:4,7:20))

write.csv(LOMBARDIA, "LOMBARDIA.csv")
write.csv(VENETO, "VENETO.csv")

REGIONS <- COVID_all[4348:4368,1:20]
POP = c(1311580, 562869,1947131,5801692,4459477,1215220,5879082,1550640,10060574,1525271,533373,305617,4356406,4029053,1639591,4999891,3729641,541380,882015,125666,4905854)
AREA=c(10795,9992,15080,13595,22451,7907,17207,5421,23861,9366,7398,4438,25399,19363,24090,25707,22993,6207,8456,3263,18316)
REGIONS$POP=POP
REGIONS$AREA=AREA
REGIONS$LETHALITY=(REGIONS$deceduti/REGIONS$POP)*1000000

REGIONS$DENSITY=REGIONS$POP/REGIONS$AREA
REGIONS$TOTCASI_R=(REGIONS$totale_casi/REGIONS$POP)*1000000
#NBA_4F$team_acr=rownames(NBA_4F)

p <- ggplot(REGIONS, aes(DENSITY,LETHALITY)) + geom_point(colour="green",size=3) + geom_text(aes(label=denominazione_regione),hjust=0, vjust=0,colour="blue")
# Add regression line
p + geom_smooth(method = lm,colour="red")

p <- ggplot(REGIONS, aes(DENSITY,deceduti)) + geom_point(colour="green",size=3) + geom_text(aes(label=denominazione_regione),hjust=0, vjust=0,colour="blue")
# Add regression line
p + geom_smooth(method = lm,colour="red")

p <- ggplot(REGIONS, aes(DENSITY,TOTCASI_R)) + geom_point(colour="green",size=3) + geom_text(aes(label=denominazione_regione),hjust=0, vjust=0,colour="blue")
# Add regression line
p + geom_smooth(method = lm,colour="red")
p <- ggplot(REGIONS, aes(DENSITY,totale_casi)) + geom_point(colour="green",size=3) + geom_text(aes(label=denominazione_regione),hjust=0, vjust=0,colour="blue")
# Add regression line
p + geom_smooth(method = lm,colour="red")



