wizualizacja-danych/proj2/projekt2.R

100 lines
2.2 KiB
R
Raw Normal View History

library(dplyr)
2021-05-26 13:17:25 +02:00
library(plotly)
2021-05-26 16:55:52 +02:00
library(mgcv)
cov <- read.csv("proj2/owid-covid-data.csv", header = TRUE)
2021-05-26 13:17:25 +02:00
cov_pl <- cov[cov$location == "Poland",]
2021-05-26 16:55:52 +02:00
# Poland - new deaths by date ---------------------------------------------
2021-05-26 13:17:25 +02:00
plot_ly(
cov_pl,
x = cov_pl$date,
y = cov_pl$new_deaths,
name = "New deaths",
type = "scatter",
mode = "lines+markers"
)
2021-05-26 16:55:52 +02:00
# Poland - new deaths vs new cases per million ----------------------------
2021-05-26 13:17:25 +02:00
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"
)
2021-05-26 16:55:52 +02:00
# Poland - vaccines by date -----------------------------------------------
2021-05-26 13:17:25 +02:00
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",
2021-05-26 13:39:43 +02:00
mode = "lines",
2021-05-26 13:17:25 +02:00
connectgaps = TRUE
)
2021-05-26 16:55:52 +02:00
# World - new deaths vs new vaccines ---------------------------------------
2021-05-26 16:55:52 +02:00
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"
)
2021-05-26 17:10:05 +02:00
# World - deaths by country -----------------------------------------------
2021-05-26 17:11:31 +02:00
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)
2021-05-26 17:10:05 +02:00
plot_ly(
2021-05-26 17:11:31 +02:00
cov_d,
x = cov_d$date,
y = cov_d$new_deaths_smoothed,
name = cov_d$location,
2021-05-26 17:10:05 +02:00
type = "scatter",
mode = "lines",
2021-05-26 17:11:31 +02:00
color = cov_d$location
2021-05-26 17:10:05 +02:00
)