Skip to content

Instantly share code, notes, and snippets.

@khalidmeister
Created May 10, 2020 09:46
Show Gist options
  • Save khalidmeister/58af9e26f85f5aca7577fdf1f9015576 to your computer and use it in GitHub Desktop.
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
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)
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)
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")
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