forked from rstats-tartu/making-plots-with-ggplot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_data.R
34 lines (27 loc) · 814 Bytes
/
get_data.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
library(here)
library(tidyverse)
library(lubridate)
library(tsibble)
url <- "https://opendata.digilugu.ee/opendata_covid19_test_results.csv"
if (!file.exists(here("data", basename(url)))) {
download.file(url, destfile = here("data", basename(url)))
}
tests <- read_csv(here("data", basename(url)))
tests <- tests %>%
distinct()
tests_sample <- tests %>%
sample_frac(0.05)
tests_sample %>%
mutate(yw = format(StatisticsDate, "%Y-%U"),
yw2 = yearweek(StatisticsDate)) %>%
group_by(yw2) %>%
count(ResultValue) %>%
ggplot() +
geom_line(aes(yw2, n, color = ResultValue))
tests_sample %>%
select(Gender, AgeGroup, Country, County, ResultValue, StatisticsDate) %>%
write_csv(here("data", "covid_tests.csv"))
n_distinct(tests$id)
tests %>%
add_count(id) %>%
filter(n > 1)