## ----setup, include=FALSE----------------------------------------------------- knitr::opts_chunk$set(echo = TRUE, eval = TRUE, fig.width = 8, fig.height = 6, warning = FALSE, message = FALSE) ## ----load-libraries, eval=TRUE, echo=TRUE------------------------------------- library(epiviz) library(dplyr) library(lubridate) ## ----explore-data, eval=TRUE, echo=TRUE--------------------------------------- # Explore the structure of lab_data glimpse(epiviz::lab_data) ## ----prepare-regional-data, eval=TRUE, echo=TRUE------------------------------ # Filter to a specific time period and aggregate by region regional_detections <- epiviz::lab_data %>% filter( specimen_date >= as.Date("2023-01-01"), specimen_date <= as.Date("2023-01-31") ) %>% count(region, name = "detections") %>% arrange(desc(detections)) %>% slice(1:6) %>% # Keep top 6 regions for readability mutate( # Handle long region names for better display region = ifelse(region == "Yorkshire and Humber", "Yorkshire and\nHumber", region) ) ## ----regional-chart, fig.width=8, fig.height=6, eval=TRUE, echo=TRUE---------- col_chart( dynamic = FALSE, # Create static ggplot chart params = list( df = regional_detections, x = "region", # Variable for x-axis y = "detections", # Variable for y-axis fill_colours = "#007C91", # Single color for all bars chart_title = "Laboratory detections by region (January 2023)", x_axis_title = "Region", y_axis_title = "Number of detections", x_axis_label_angle = -45, # Rotate labels for readability show_gridlines = FALSE # Remove grid lines for cleaner look ) ) ## ----prepare-monthly-data, eval=TRUE, echo=TRUE------------------------------- # Aggregate detections by month monthly_detections <- epiviz::lab_data %>% filter( specimen_date >= as.Date("2022-01-01"), specimen_date <= as.Date("2023-12-31") ) %>% mutate( specimen_month = floor_date(specimen_date, "month") ) %>% count(specimen_month, name = "detections") ## ----monthly-line-chart, fig.width=8, fig.height=6, eval=TRUE, echo=TRUE------ line_chart( dynamic = FALSE, # Create static ggplot chart params = list( dfr = monthly_detections, # Note: use 'dfr' parameter for line_chart x = "specimen_month", # Date variable for x-axis y = "detections", # Count variable for y-axis line_colour = c("#007C91"), # Color for the line (vector format) line_type = c("solid") # Line type ) )