From 6eb390fb21fd46ed23974d0b7849f590b510831d Mon Sep 17 00:00:00 2001 From: nlitkowski Date: Wed, 26 May 2021 16:55:52 +0200 Subject: [PATCH] Add new plot --- proj2/projekt2.R | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/proj2/projekt2.R b/proj2/projekt2.R index af9b881..b9d99f6 100644 --- a/proj2/projekt2.R +++ b/proj2/projekt2.R @@ -1,10 +1,13 @@ library(dplyr) library(plotly) +library(mgcv) cov <- read.csv("proj2/owid-covid-data.csv", header = TRUE) cov_pl <- cov[cov$location == "Poland",] +# Poland - new deaths by date --------------------------------------------- + plot_ly( cov_pl, x = cov_pl$date, @@ -14,6 +17,8 @@ plot_ly( mode = "lines+markers" ) +# Poland - new deaths vs new cases per million ---------------------------- + plot_ly( cov_pl, x = cov_pl$date, @@ -29,6 +34,8 @@ plot_ly( mode = "lines+markers" ) +# Poland - vaccines by date ----------------------------------------------- + cov_pl_vac = cov_pl[as.POSIXct(cov_pl$date) > as.POSIXct('2020-12-12'),] plot_ly( @@ -48,5 +55,29 @@ plot_ly( connectgaps = TRUE ) +# World - new deaths vs new vaccines --------------------------------------- +cov_vac <- cov[as.POSIXct(cov$date) > as.POSIXct('2020-12-12'),] +cov_vac[["new_vaccinations"]][is.na(cov_vac[["new_vaccinations"]])] <- 0 +cov_vac[["new_deaths"]][is.na(cov_vac[["new_deaths"]])] <- 0 +df <- data.frame( + date=cov_vac$date, + new_deaths=cov_vac$new_deaths, + new_vaccinations=cov_vac$new_vaccinations + ) +df <- df %>% + group_by(date) + +plot_ly( + df, + x = df$date, + y = df$new_deaths, + name = "New deaths", + type = "scatter", + mode = "lines" +) %>% + add_lines( + y = df$new_vaccinations, + name = "New vaccines" + )