Created
May 10, 2020 09:46
-
-
Save khalidmeister/58af9e26f85f5aca7577fdf1f9015576 to your computer and use it in GitHub Desktop.
Tidy Data: Why We Should Invest On It and How to Do it
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(readr) | |
confirmed <- 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") | |
head(confirmed) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
x <- as.Date(colnames(confirmed)[5:length(colnames(confirmed))], format="%m/%d/%y") | |
y <- confirmed[confirmed$`Country/Region` == "Indonesia", 5:length(colnames(confirmed))] | |
plot(x, y) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(dplyr) | |
library(ggplot2) | |
asean <- c("Indonesia", "Singapore", "Vietnam", "Malaysia", "Thailand") | |
confirmed_tidy %>% | |
filter(country %in% asean) %>% | |
ggplot(aes(x=date, y=total, color=country)) + | |
geom_line(size=1.5) + | |
ggtitle("COVID-19 Cases", subtitle = "Indonesia, Malaysia, Singapore, Thailand, Vietnam") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(tidyr) | |
confirmed_tidy <- confirmed %>% | |
pivot_longer(5:(length(colnames(confirmed))), names_to = "date", values_to = "total") | |
colnames(confirmed_tidy) <- c("province", "country", "lat", "long", "date", "total") | |
confirmed_tidy$date <- as.Date(confirmed_tidy$date, format="%m/%d/%y") | |
confirmed_tidy |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment