Skip to content

Commit ad51303

Browse files
authored
Merge pull request #13 from epiforecasts/11-first-data-fig
Issue 11: add first draft of first fig
2 parents 24f17fc + e63f942 commit ad51303

19 files changed

+1161
-30
lines changed

DESCRIPTION

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ Imports:
2929
roxyglobals,
3030
data.table,
3131
rlang,
32+
cowplot,
3233
lubridate
3334
Suggests:
3435
bookdown,

NAMESPACE

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ importFrom(ggplot2,vars)
3131
importFrom(ggplot2,xlab)
3232
importFrom(ggplot2,ylab)
3333
importFrom(lubridate,days)
34+
importFrom(lubridate,epiweek)
35+
importFrom(lubridate,epiyear)
3436
importFrom(lubridate,ymd)
3537
importFrom(rlang,arg_match)
3638
importFrom(rlang,sym)

R/daily_to_weekly.R

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#' Convert sequence data from daily to weekly
2+
#'
3+
#' @param daily_data Data.frame of sequence counts by location and clade
4+
#'
5+
#' @returns Data aggregated by epiweek.
6+
#' @importFrom lubridate epiweek epiyear
7+
daily_to_weekly <- function(daily_data) {
8+
date_spine <- tibble(
9+
date = seq(
10+
from = min(daily_data$date),
11+
to = max(daily_data$date), by = "day"
12+
)
13+
) |>
14+
mutate(
15+
epi_week = epiweek(date),
16+
epi_year = epiyear(date),
17+
wday = wday(date, label = TRUE)
18+
) |>
19+
filter(wday == "Sat")
20+
21+
metadata <- daily_data |>
22+
select(location, location_name, location_code, population, type) |>
23+
unique()
24+
weekly_data <- daily_data |>
25+
mutate(
26+
epi_week = epiweek(date),
27+
epi_year = epiyear(date)
28+
) |>
29+
group_by(
30+
epi_year, epi_week,
31+
location, clades_modeled
32+
) |>
33+
summarise(
34+
sequences = sum(sequences),
35+
.groups = "drop"
36+
) |>
37+
left_join(date_spine, by = c("epi_week", "epi_year")) |>
38+
left_join(metadata, by = "location")
39+
return(weekly_data)
40+
}

0 commit comments

Comments
 (0)