## ----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) ## ----prepare-single-series, eval=TRUE, echo=TRUE------------------------------ # Filter and aggregate data for a single organism (as used in tests) single_series_data <- epiviz::lab_data %>% filter( organism_species_name == "KLEBSIELLA PNEUMONIAE", specimen_date >= as.Date("2023-01-01"), specimen_date <= as.Date("2023-01-31") ) %>% group_by(specimen_date) %>% summarise(count = n(), .groups = 'drop') %>% as.data.frame() # Ensure it's a data frame ## ----single-series-line-chart, fig.cap="Daily detections of Klebsiella pneumoniae in January 2023.", fig.alt="Line chart showing daily counts of Klebsiella pneumoniae detections across January 2023."---- line_chart( dynamic = FALSE, # Create static ggplot chart params = list( df = single_series_data, # Note: use 'dfr' parameter (as in tests) x = "specimen_date", # Date variable for x-axis y = "count", # Count variable for y-axis line_colour = c("blue"), # Single color for single line line_type = c("solid") # Line type ) ) ## ----prepare-multi-series, eval=TRUE, echo=TRUE------------------------------- # Aggregate data for multiple organisms (as used in tests) multi_series_data <- epiviz::lab_data %>% group_by(organism_species_name, specimen_date) %>% summarise(count = n(), .groups = 'drop') %>% ungroup() %>% filter( specimen_date >= as.Date("2023-12-01"), specimen_date <= as.Date("2023-12-31") ) %>% as.data.frame() # Ensure it's a data frame ## ----multi-series-line-chart, fig.cap="Daily detections by organism species across the month of December 2023.", fig.alt="Line chart with multiple coloured lines representing daily laboratory detections for several organism species during December 2023."---- line_chart( dynamic = FALSE, # Create static ggplot chart params = list( df = multi_series_data, # Use 'df' parameter x = "specimen_date", # Date variable for x-axis y = "count", # Count variable for y-axis group_var = "organism_species_name", # Group by organism type line_colour = c("blue", "green", "orange"), # Colors for each organism line_type = c("solid", "dotted", "dashed") # Different line styles ) ) ## ----interactive-multi-series-line-chart, fig.cap="Interactive comparison of organism-specific detections across December 2023.", fig.alt="Interactive line chart with multiple series showing laboratory detections by organism across December 2023."---- line_chart( dynamic = TRUE, # Create interactive plotly chart params = list( df = multi_series_data, # Use 'df' parameter x = "specimen_date", # Date variable for x-axis y = "count", # Count variable for y-axis group_var = "organism_species_name", # Group by organism type line_colour = c("blue", "green", "orange"), # Colors for each organism line_type = c("solid", "dotted", "dashed") # Different line styles ) ) ## ----prepare-enhanced-series, eval=TRUE, echo=TRUE---------------------------- # Create a focused dataset for enhanced styling enhanced_data <- epiviz::lab_data %>% filter( organism_species_name == "STAPHYLOCOCCUS AUREUS", specimen_date >= as.Date("2023-06-01"), specimen_date <= as.Date("2023-08-31") ) %>% mutate( specimen_week = floor_date(specimen_date, "week", week_start = 1) # Monday start ) %>% count(specimen_week, name = "detections") ## ----enhanced-line-chart, fig.cap="Weekly Staphylococcus aureus detections during summer 2023.", fig.alt="Line chart showing weekly detections of Staphylococcus aureus from June to August 2023 with custom styling."---- line_chart( dynamic = FALSE, # Create static ggplot chart params = list( dfr = enhanced_data, # Use 'dfr' parameter x = "specimen_week", # Weekly date variable y = "detections", # Count variable line_colour = c("#FF7F32"), # Orange color line_type = c("solid"), # Solid line # Additional styling parameters (if supported by the function) chart_title = "Weekly Staph aureus detections (Summer 2023)", x_axis_title = "Week", y_axis_title = "Number of detections", x_axis_label_angle = -45, show_gridlines = TRUE, y_axis_limits = c(0, NA) ) )