This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.
When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
options(repos = c(CRAN = 'mirror_url'))
install.packages("tidyverse")
## Warning: unable to access index for repository mirror_url/src/contrib:
## cannot open URL 'mirror_url/src/contrib/PACKAGES'
## Warning: package 'tidyverse' is not available for this version of R
##
## A version of this package for your version of R might be available elsewhere,
## see the ideas at
## https://cran.r-project.org/doc/manuals/r-patched/R-admin.html#Installing-packages
## Warning: unable to access index for repository mirror_url/bin/macosx/big-sur-x86_64/contrib/4.3:
## cannot open URL 'mirror_url/bin/macosx/big-sur-x86_64/contrib/4.3/PACKAGES'
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.3 ✔ readr 2.1.4
## ✔ forcats 1.0.0 ✔ stringr 1.5.0
## ✔ ggplot2 3.4.4 ✔ tibble 3.2.1
## ✔ lubridate 1.9.3 ✔ tidyr 1.3.0
## ✔ purrr 1.0.2
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
url <- "https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/time_series_covid19_confirmed_global.csv"
download.file(url, destfile = "covid_data_selected.csv", mode = "wb")
covid_data <- read.csv(url)
selected_columns <- c("Country.Region", "Province.State", names(covid_data)[5:length(covid_data)])
covid_data_selected <- covid_data %>%
select(all_of(selected_columns)) %>%
gather(key = "Date", value = "ConfirmedCases", -c("Country.Region", "Province.State")) %>%
rename("Deaths" = "ConfirmedCases")
covid_data_selected$Date <- as.Date(covid_data_selected$Date, format = "%m/%d/%y")
write.csv(covid_data_selected, "covid_data_selected.csv", row.names = FALSE)
install.packages("ggplot2")
## Warning: unable to access index for repository mirror_url/src/contrib:
## cannot open URL 'mirror_url/src/contrib/PACKAGES'
## Warning: package 'ggplot2' is not available for this version of R
##
## A version of this package for your version of R might be available elsewhere,
## see the ideas at
## https://cran.r-project.org/doc/manuals/r-patched/R-admin.html#Installing-packages
## Warning: unable to access index for repository mirror_url/bin/macosx/big-sur-x86_64/contrib/4.3:
## cannot open URL 'mirror_url/bin/macosx/big-sur-x86_64/contrib/4.3/PACKAGES'
library(ggplot2)
covid_data <- read.csv("covid_data_selected.csv")
str(covid_data)
## 'data.frame': 330327 obs. of 4 variables:
## $ Country.Region: chr "Afghanistan" "Albania" "Algeria" "Andorra" ...
## $ Province.State: chr "" "" "" "" ...
## $ Date : logi NA NA NA NA NA NA ...
## $ Deaths : int 0 0 0 0 0 0 0 0 0 0 ...
summary(covid_data)
## Country.Region Province.State Date Deaths
## Length:330327 Length:330327 Mode:logical Min. : 0
## Class :character Class :character NA's:330327 1st Qu.: 680
## Mode :character Mode :character Median : 14429
## Mean : 959384
## 3rd Qu.: 228517
## Max. :103802702
head(covid_data)
## Country.Region Province.State Date Deaths
## 1 Afghanistan NA 0
## 2 Albania NA 0
## 3 Algeria NA 0
## 4 Andorra NA 0
## 5 Angola NA 0
## 6 Antarctica NA 0
ggplot(covid_data, aes(x = Date)) +
geom_line(aes(y = Country.Region, color = "Country.Region"), size = 1) +
geom_line(aes(y = Deaths, color = "Deaths"), size = 1) +
labs(title = "COVID-19 Time Series Chart",
x = "Date",
y = "Quantity") +
theme_minimal()
## Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
## ℹ Please use `linewidth` instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.