link1 <- "https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/time_series_19-covid-Recovered.csv"
link2 <- "https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/time_series_19-covid-Confirmed.csv"
link3 <-"https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/time_series_19-covid-Deaths.csv"link1 %>%
read_csv() %>%
rename(Province = `Province/State`, Country = `Country/Region`) %>%
gather(Date, Recovered, -Province, -Country, -Lat, -Long) %>%
mutate(Date = mdy(Date)) -> df_recovered
datatable(df_recovered)link2 %>%
read_csv() %>%
rename(Province = `Province/State`, Country = `Country/Region`) %>%
gather(Date, Confirmed, -Province, -Country, -Lat, -Long) %>%
mutate(Date = mdy(Date)) -> df_confirmed
datatable(df_confirmed)link3 %>%
read_csv() %>%
rename(Province = `Province/State`, Country = `Country/Region`) %>%
gather(Date, Death, -Province, -Country, -Lat, -Long) %>%
mutate(Date = mdy(Date)) -> df_Death
datatable(df_Death)df_recovered %>%
filter(Date ==end_date) %>%
group_by(Country) %>%
mutate(Totalrecov = sum(Recovered)) %>%
ungroup() %>%
filter(!duplicated(Country)) %>%
select(Country, Totalrecov) -> recovered_0305
datatable(recovered_0305)df_confirmed %>%
filter(Date == end_date) %>%
group_by(Country) %>%
mutate(Total_con = sum(Confirmed)) %>%
ungroup() %>%
filter(!duplicated(Country)) %>%
select(Country,Total_con) ->confirmed_0305
datatable(confirmed_0305)df_Death %>%
filter(Date == end_date) %>%
group_by(Country) %>%
mutate(Total_death = sum(Death)) %>%
select(Country, Total_death) ->Death_0305
datatable(Death_0305)## 데이터 합치기
full_join(confirmed_0305, recovered_0305, by = "Country") %>%
mutate(Cases = Total_con - Totalrecov) -> df_type1
full_join(df_type1, Death_0305, by="Country") %>%
mutate(death_rate= Total_death/ Total_con *100) %>%
mutate(death_rate = round(death_rate,1))-> df_final
datatable(df_final)df_final %>%
mutate(Country = case_when(Country %in% c("Mainland China", "Macau", "Hong Kong") ~ "China",
Country == "US" ~ "United States",
Country == "UK" ~ "United Kingdom",
TRUE ~ Country)) %>%
group_by(Country) %>%
summarise(Case_Number = sum(Cases)) %>%
ungroup() %>%
mutate(iso3 = countrycode(Country, origin = "country.name", destination = "iso3c")) -> df_final2
df_final2## # A tibble: 147 x 3
## Country Case_Number iso3
## <chr> <dbl> <chr>
## 1 Afghanistan 1 AFG
## 2 Albania 0 ALB
## 3 Algeria 12 DZA
## 4 Andorra 1 AND
## 5 Antigua and Barbuda 0 ATG
## 6 Argentina 1 ARG
## 7 Armenia 1 ARM
## 8 Aruba 0 ABW
## 9 Australia 306 AUS
## 10 Austria 41 AUT
## # ... with 137 more rows
highchart(type="map") %>%
hc_add_series_map(map = worldgeojson, df = df_final2, value = "Case_Number", joinBy = "iso3") %>%
hc_colorAxis(stops = color_stops()) %>%
hc_title(text = "Corona Virus Prevalence by Country as of 05-03-2020",
style = list(fontSize = "24px")) %>%
hc_credits(enabled = TRUE, style = list(fontSize = "12px"),
text = "Source: Johns Hopkins University Center for Systems Science and Engineering") %>%
hc_tooltip(useHTML = TRUE, headerFormat = "",
pointFormat = "Country: {point.Country}, Number of Corona Cases: {point.N_cases}") %>%
hc_add_theme(hc_theme_flatdark())# 1월 30일을 기점으로 하는 데이터만 뽑음
start_date <- ymd("2020-01-30")
df_recovered %>%
filter(Date >= start_date) %>%
group_by(Date, Country) %>%
mutate(Total_recov = sum(Recovered)) %>%
select(-Province, -Lat, -Long, - Recovered) -> Recov
df_confirmed %>%
filter(Date >= start_date) %>%
group_by(Date, Country) %>%
mutate(Total_conf = sum(Confirmed)) %>%
select(-Province, -Lat, -Long, - Confirmed) -> Conf
df_Death %>%
filter(Date >= start_date) %>%
group_by(Date, Country) %>%
mutate(Total_death = sum(Death)) %>%
select(-Province, -Lat, -Long, - Death) -> Death
Conf %>%
group_by(Date, Country) %>%
filter(Country == "Korea, South") -> Korea
Korea## # A tibble: 46 x 3
## # Groups: Date, Country [46]
## Country Date Total_conf
## <chr> <date> <dbl>
## 1 Korea, South 2020-01-30 4
## 2 Korea, South 2020-01-31 11
## 3 Korea, South 2020-02-01 12
## 4 Korea, South 2020-02-02 15
## 5 Korea, South 2020-02-03 15
## 6 Korea, South 2020-02-04 16
## 7 Korea, South 2020-02-05 19
## 8 Korea, South 2020-02-06 23
## 9 Korea, South 2020-02-07 24
## 10 Korea, South 2020-02-08 24
## # ... with 36 more rows
Korea %>%
hchart('line', hcaes(x = 'Date', y = 'Total_conf'), name="The Number of Cases") %>%
hc_title(text ="Accumulative Corona Confirmed Cases of South Korea",
style = list(color = "white",useHTML = TRUE)) %>%
hc_subtitle(text="Source : refer to the links", color="white") %>% hc_add_theme(hc_theme_flatdark())Conf %>%
group_by(Date, Country) %>%
filter(Country %in% c("Korea, South", "Japan")) ->Asia_Table
Asia_Table## # A tibble: 92 x 3
## # Groups: Date, Country [92]
## Country Date Total_conf
## <chr> <date> <dbl>
## 1 Japan 2020-01-30 11
## 2 Korea, South 2020-01-30 4
## 3 Japan 2020-01-31 15
## 4 Korea, South 2020-01-31 11
## 5 Japan 2020-02-01 20
## 6 Korea, South 2020-02-01 12
## 7 Japan 2020-02-02 20
## 8 Korea, South 2020-02-02 15
## 9 Japan 2020-02-03 20
## 10 Korea, South 2020-02-03 15
## # ... with 82 more rows
Asia_Table %>%
hchart('line', hcaes(x="Date", y="Total_conf", group= "Country")) %>%
hc_tooltip(crosshairs = TRUE, borderWidth = 1.5,
headerFormat = "", pointFormat = paste("Year: <b>{point.x}</b> <br>","Gender: <b>{point.sex}</b><br>",
"Suicides: <b>{point.y}</b>")) %>%
hc_title(text = "Accumulative Corona Confirmed Cases of South Korea & Japan") %>%
hc_subtitle(text = "From 2020-01-30") %>%
hc_xAxis(title = list(text = "Year")) %>%
hc_yAxis(titla = list(text= "Number of Cases"))## 1월 30일 이후 사망자가 가장 많이 나온 나라
Death[order(Death$Total_death, decreasing = T),] %>%
group_by(Country) %>%
filter(!duplicated(Country))%>%
filter(Total_death >= 10) -> dd
highchart() %>%
hc_add_series(dd, hcaes(x= factor(Country), y=Total_death, color=Total_death), type="bar") %>%
hc_tooltip(borderWidth = 1.8, pointFormat = paste("The Number of Death :<b>{point.y}</b>")) %>%
hc_legend(enabled = FALSE) %>%
hc_title(text = "Death Rate of countries") %>%
hc_subtitle(text = "Since 2020-01-30") %>%
hc_xAxis(categories = dd$Country, scrollbar = list(enabled = TRUE)) %>%
hc_yAxis(title = list(text = "Death Rate per 100K people")) %>%
hc_plotOptions(bar = list(stacking = "normal",
pointPadding = 0, groupPadding = 0, borderWidth = 0.5))