wizualizacja-danych/proj2/projekt2.R
2021-05-26 17:10:05 +02:00

96 lines
2.0 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 -----------------------------------------------
plot_ly(
cov,
x = cov$date,
y = cov$new_deaths,
name = "New deaths",
type = "scatter",
mode = "lines",
connect_gaps = TRUE,
color = cov$location
)