library(tidyverse)
## ── Attaching packages ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── tidyverse 1.3.0 ──
## ✓ ggplot2 3.2.1 ✓ 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
## ── Conflicts ────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── tidyverse_conflicts() ──
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
corona_data <- read_csv("COVID-19-master/csse_covid_19_data/csse_covid_19_time_series/time_series_19-covid-Confirmed.csv")
## Parsed with column specification:
## cols(
## .default = col_double(),
## `Province/State` = col_character(),
## `Country/Region` = col_character()
## )
## See spec(...) for full column specifications.
(data <- corona_data %>%
filter(`Country/Region` == "Germany" | `Country/Region` == "Italy" | `Country/Region` == "China" | `Country/Region` == "US" | `Country/Region` == "France") %>%
select(-`Province/State`) %>%
select(-Lat,-Long) %>%
group_by(`Country/Region`) %>%
summarise_each(funs(sum))
)
## Warning: funs() is soft deprecated as of dplyr 0.8.0
## Please use a list of either functions or lambdas:
##
## # Simple named list:
## list(mean = mean, median = median)
##
## # Auto named with `tibble::lst()`:
## tibble::lst(mean, median)
##
## # Using lambdas
## list(~ mean(., trim = .2), ~ median(., na.rm = TRUE))
## This warning is displayed once per session.
# first remember the names
n <- data$`Country/Region`
# transpose all but the first column (name)
data <- as.data.frame(t(data[,-1]))
colnames(data) <- n
data <- tibble::rownames_to_column(data, "Day")
#data$myfactor <- factor(row.names(data))
str(data) # Check the column types
## 'data.frame': 56 obs. of 6 variables:
## $ Day : chr "1/22/20" "1/23/20" "1/24/20" "1/25/20" ...
## $ China : num 548 643 920 1406 2075 ...
## $ France : num 0 0 2 3 3 3 4 5 5 5 ...
## $ Germany: num 0 0 0 0 0 1 4 4 4 5 ...
## $ Italy : num 0 0 0 0 0 0 0 0 0 2 ...
## $ US : num 1 1 2 2 5 5 5 5 5 7 ...
data <- data %>%
mutate(Day = as.Date(Day,"%m/%d/%y"))
library(reshape2)
##
## Attaching package: 'reshape2'
## The following object is masked from 'package:tidyr':
##
## smiths
d <- melt(data, id.vars="Day")
ggplot(d, aes(Day,value, col=variable)) +
geom_line()
(d2 <- d %>%
filter(value > 19) %>%
group_by(variable) %>%
mutate(id = row_number()))
ggplot(d2, aes(id,value, col=variable)) +
geom_line()