knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)

In which Week happended the most slides

library(iffitoR)
library(lubridate)
library(stringr)
library(leaflet.extras)
library(sf)
library(leaflet)
library(dplyr)
library(ggplot2)
library(glue)
library(forcats)
data_iffi = landsld
glimpse(data_iffi)

Max Slides per Day

data_iffi %>% 
  filter(str_detect(second_level, "translational")) %>% 
  count(date, sort=T)

Visualize the max slides per day

dat = data_iffi %>% 
  filter(date == as.Date("2020-12-06")) %>% 
  st_transform(4326)


# the color palette for the categorical data 
cf = colorFactor(palette = "RdYlBu", domain=dat$second_level)
sl = unique(dat$second_level)

map = leaflet(dat) %>%
  addProviderTiles(providers$Stamen.TonerLite) 

for (g in sl) {
  d = dat %>% filter(second_level == g)
  map = map %>% addCircles(
    data = d,
    popup = paste0("date: ", d$date, "<br>", "type:", d$second_level),
    color =  ~ cf(d$second_level),
    group = g
  )
}

map %>% addLayersControl(overlayGroups = sl) 

Aggregate per week

library(showtext)
library(extrafont)
loadfonts()

data_iffi %>% 
  filter(date_info == "day") %>% 
  filter(str_detect(second_level, "translational")) %>% 
  mutate(week = paste0(year.int, formatC(week(date), flag=0, width=2))) %>% 
  count(week, sort=T) %>% 
  mutate(first_day_of_week = as.Date(paste0(week, 1), "%Y%U%u")) %>% 
  mutate(week = glue("{first_day_of_week}  ({n})")) %>% 
  mutate(week = fct_reorder(week, n)) %>% 
  head(n = 12) %>% 
  ggplot() +
  geom_col(aes(x=n, y=week), color="black") +
  theme_light(base_family="Times New Roman") +
  labs(x = "# of events per week",
       y = "Week",
       title = "Weeks with highest number of Slides") +
  theme(
    axis.title.y = element_blank()
  )


RobinKohrs/iffitoR documentation built on Sept. 7, 2021, 11:31 p.m.