wizualizacja-danych/proj2/projekt2.R
nlitkowski 76257ec14b update
2021-05-26 17:11:31 +02:00

100 lines
2.2 KiB
R

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,
y = cov_pl$new_deaths,
name = "New deaths",
type = "scatter",
mode = "lines+markers"
)
# Poland - new deaths vs new cases per million ----------------------------
plot_ly(
cov_pl,
x = cov_pl$date,
y = cov_pl$new_deaths_per_million,
name = "New deaths per million",
type = "scatter",
mode = "lines+markers"
) %>%
add_trace(
y = cov_pl$new_cases_per_million,
name = "New cases per million",
type = "scatter",
mode = "lines+markers"
)
# Poland - vaccines by date -----------------------------------------------
cov_pl_vac = cov_pl[as.POSIXct(cov_pl$date) > as.POSIXct('2020-12-12'),]
plot_ly(
cov_pl_vac,
x = cov_pl_vac$date,
y = cov_pl_vac$people_vaccinated,
name = "People vaccinated",
type = "scatter",
mode = "lines",
connectgaps = TRUE
) %>%
add_trace(
y = cov_pl_vac$people_fully_vaccinated,
name = "People fully vaccinated",
type = "scatter",
mode = "lines",
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"
)
# World - deaths by country -----------------------------------------------
cov_d <- cov
cov_d[["new_vaccinations"]][is.na(cov_d[["new_vaccinations"]])] <- 0
cov_d[["new_deaths"]][is.na(cov_d[["new_deaths"]])] <- 0
cov_d <- cov_d %>% group_by(location)
plot_ly(
cov_d,
x = cov_d$date,
y = cov_d$new_deaths_smoothed,
name = cov_d$location,
type = "scatter",
mode = "lines",
color = cov_d$location
)