library(janitor)
## Warning: package 'janitor' was built under R version 3.6.3
##
## Attaching package: 'janitor'
## The following objects are masked from 'package:stats':
##
## chisq.test, fisher.test
library(tidyverse)
## Warning: package 'tidyverse' was built under R version 3.6.1
## -- Attaching packages ------------------------------------------------------ tidyverse 1.2.1 --
## √ ggplot2 3.3.0 √ purrr 0.3.3
## √ tibble 2.1.3 √ dplyr 0.8.3
## √ tidyr 1.0.0 √ stringr 1.4.0
## √ readr 1.3.1 √ forcats 0.4.0
## Warning: package 'tibble' was built under R version 3.6.2
## Warning: package 'tidyr' was built under R version 3.6.1
## Warning: package 'purrr' was built under R version 3.6.2
## Warning: package 'dplyr' was built under R version 3.6.2
## -- Conflicts --------------------------------------------------------- tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
library(highcharter)
## Warning: package 'highcharter' was built under R version 3.6.3
## Registered S3 method overwritten by 'xts':
## method from
## as.zoo.xts zoo
## Registered S3 method overwritten by 'quantmod':
## method from
## as.zoo.data.frame zoo
## Highcharts (www.highcharts.com) is a Highsoft software product which is
## not free for commercial and Governmental use
library(lubridate)
##
## Attaching package: 'lubridate'
## The following object is masked from 'package:base':
##
## date
library(gridExtra)
##
## Attaching package: 'gridExtra'
## The following object is masked from 'package:dplyr':
##
## combine
R Markdown
corona <- read_csv("covid_19_data.csv")
## Parsed with column specification:
## cols(
## SNo = col_double(),
## ObservationDate = col_character(),
## `Province/State` = col_character(),
## `Country/Region` = col_character(),
## `Last Update` = col_character(),
## Confirmed = col_double(),
## Deaths = col_double(),
## Recovered = col_double()
## )
head(corona)
## # A tibble: 6 x 8
## SNo ObservationDate `Province/State` `Country/Region` `Last Update`
## <dbl> <chr> <chr> <chr> <chr>
## 1 1 01/22/2020 Anhui Mainland China 1/22/2020 17~
## 2 2 01/22/2020 Beijing Mainland China 1/22/2020 17~
## 3 3 01/22/2020 Chongqing Mainland China 1/22/2020 17~
## 4 4 01/22/2020 Fujian Mainland China 1/22/2020 17~
## 5 5 01/22/2020 Gansu Mainland China 1/22/2020 17~
## 6 6 01/22/2020 Guangdong Mainland China 1/22/2020 17~
## # ... with 3 more variables: Confirmed <dbl>, Deaths <dbl>,
## # Recovered <dbl>
corona$`Country/Region`[corona$`Country/Region` == "Mainland China"] = "China"
corona$`Country/Region`[corona$`Country/Region` == "US"] = "United States of America"
#political sxxt for Taipei and environ
corona %>% group_by(`Country/Region`) %>%
summarise(Tconfirmed = sum(Confirmed)) %>%
filter(`Country/Region` == 'Taiwan' | `Country/Region` =='Taipei and environs') ->
Taiwan
Taiwan
## # A tibble: 2 x 2
## `Country/Region` Tconfirmed
## <chr> <dbl>
## 1 Taipei and environs 47
## 2 Taiwan 1057
#Change name right
corona$`Country/Region`[corona$`Country/Region` == "Taiwan"] = "China"
corona$`Country/Region`[corona$`Country/Region` == "Taipei and environs"] = "Taiwan"
#Count sum of confirmed/recover/rate of recover
corona %>%
janitor::clean_names() %>%
filter(!country_region %in% 'Others') %>%
group_by(country_region) %>%
summarise(total_confirmed = sum(confirmed),
total_recovered = sum(recovered),
total_death = sum(deaths)) %>%
filter(total_confirmed > 0) %>%
mutate(log_total_confirmed = log(total_confirmed)) -> countries_confirmed
head(countries_confirmed)
## # A tibble: 6 x 5
## country_region total_confirmed total_recovered total_death
## <chr> <dbl> <dbl> <dbl>
## 1 Afghanistan 26 0 0
## 2 Albania 12 0 0
## 3 Algeria 131 0 0
## 4 Andorra 9 0 0
## 5 Argentina 54 0 3
## 6 Armenia 10 0 0
## # ... with 1 more variable: log_total_confirmed <dbl>
#plot T-confirmed in world
highchart() %>%
hc_add_series_map(worldgeojson, countries_confirmed, value = 'total_confirmed', joinBy = c('name','country_region')) %>%
#hc_colors(c("darkorange", "darkgray")) %>%
hc_colorAxis(stops = color_stops()) %>%
hc_title(text = "Countries with nCov exposure") %>%
hc_subtitle(text = 'with Total Confirmed - Actual Figures')
#Top 10 country of confirmed
countries_confirmed %>%
group_by(country_region) %>%
arrange(desc(total_confirmed)) %>%
head(10) %>%
hchart("bar",hcaes(x = country_region, y =total_confirmed)) %>%
hc_add_theme(hc_theme_sandsignika())
## Warning: `parse_quosure()` is deprecated as of rlang 0.2.0.
## Please use `parse_quo()` instead.
## This warning is displayed once per session.
#With Date
corona %>%
group_by(ObservationDate) %>%
summarise(total_confirmed = sum(Confirmed),
total_recovered = sum(Recovered),
total_deaths = sum(Deaths))->Date_confirmed
Date_confirmed$Date <- as.Date(Date_confirmed$ObservationDate, format = "%m/%d/%y")
head(Date_confirmed)
## # A tibble: 6 x 5
## ObservationDate total_confirmed total_recovered total_deaths Date
## <chr> <dbl> <dbl> <dbl> <date>
## 1 01/22/2020 555 28 17 2020-01-22
## 2 01/23/2020 653 30 18 2020-01-23
## 3 01/24/2020 941 36 26 2020-01-24
## 4 01/25/2020 1438 39 42 2020-01-25
## 5 01/26/2020 2118 52 56 2020-01-26
## 6 01/27/2020 2927 61 82 2020-01-27
#confirmed
C <- ggplot(Date_confirmed, aes(Date, total_confirmed))+
geom_line(size = 2, alpha = 0.8,color = "#FC4E07")+
geom_point(shape=21, color="black", fill="blue", size=6) +
scale_x_date(date_labels = "%b %d", date_breaks = "7 days")
#revovered
R <- ggplot(Date_confirmed, aes(Date, total_recovered))+
geom_line(size = 2, alpha = 0.8,color = "#FC4E07")+
geom_point(shape=21, color="black", fill="blue", size=6) +
scale_x_date(date_labels = "%b %d", date_breaks = "7 days")
#deaths
D <- ggplot(Date_confirmed, aes(Date, total_deaths))+
geom_line(size = 2, alpha = 0.8,color = "#FC4E07")+
geom_point(shape=21, color="black", fill="blue", size=6) +
scale_x_date(date_labels = "%b %d", date_breaks = "7 days")
grid.arrange(C, R, D,ncol=1)
