Intro Thoughts

Status Quo

library(tidyverse)
library(ggswim)

library(ggplot2)

p1 <- ggplot() +
  geom_swim_lane(
    data = patient_data,
    mapping = aes(
      x = start_time, y = pt_id, xend = end_time,
      colour = disease_assessment
    )) 
p1

# Construct arrow_data for arrow display later
arrow_data <- patient_data |>
  dplyr::left_join(
    end_study_events |>
      dplyr::select(pt_id, label),
    by = "pt_id"
  ) |>
  dplyr::select(pt_id, end_time, label) |>
  dplyr::filter(.by = pt_id, end_time == max(end_time)) |>
  dplyr::filter(is.na(label)) |>
  unique()



p2 <- ggplot() +
  geom_swim_arrow(
    data = arrow_data,
    mapping = aes(xend = end_time, y = pt_id)
  ) +
  scale_colour_brewer(
    name = "Disease Assessments",
    palette = "Set1"
  )
p2

all_events <- dplyr::bind_rows(
  infusion_events,
  end_study_events
)

head(all_events)
## # A tibble: 6 × 5
##   pt_id time_from_initial_infusion label             glyph colour 
##   <chr>                      <dbl> <chr>             <chr> <chr>  
## 1 01                             1 First Reinfusion  ⬤     #999999
## 2 02                             0 First Reinfusion  ⬤     #999999
## 3 03                             2 First Reinfusion  ⬤     #999999
## 4 03                             3 Second Reinfusion ⬤     #f57dc1
## 5 04                             5 First Reinfusion  ⬤     #999999
## 6 05                             2 First Reinfusion  ⬤     #999999
p3 <- ggplot() +
  geom_swim_marker(
    data = all_events,
    aes(x = time_from_initial_infusion, y = pt_id, marker = label),
    size = 5
  )
p3

library(patchwork)
p1 / p2 / p3

all_events %>% 
  distinct(glyph, colour, label) ->
marker_dictionary
  
marker_dictionary
## # A tibble: 5 × 3
##   glyph colour  label                    
##   <chr> <chr>   <chr>                    
## 1 ⬤     #999999 First Reinfusion         
## 2 ⬤     #f57dc1 Second Reinfusion        
## 3 ⚠️     <NA>    Other End Study Reason   
## 4 ❌    <NA>    Deceased                 
## 5 ✅    <NA>    Completed Study Follow-Up
p4 <- p3 +
  scale_marker_discrete(
    glyphs = marker_dictionary$glyph,
    colours = marker_dictionary$colour,
    limits = marker_dictionary$label,
    name = "Study Events"
  )

p4

library(ggplot2)
library(ggswim)
geom_marker <- geom_swim_marker

mtcars |>
  ggplot() +
  aes(x = wt, y = mpg, marker = factor(am)) +
  geom_marker(size = 8) + 
  scale_marker_discrete(
    limits = 0:1,
    colours = c("orange", "midnightblue")
  )
## Warning in scale_marker_discrete(limits = 0:1, colours = c("orange", "midnightblue")): Continuous limits supplied to discrete scale.
## ℹ Did you mean `limits = factor(...)` or `scale_*_continuous()`?

# scale_marker_discrete(
#     limits = c("First Reinfusion",         
#                "Second Reinfusion",         
#                "Other End Study Reason", 
#                "Deceased",
#                "Completed Study Follow-Up"),
#     glyphs = c( "⬤" , "⬤"  ,"⚠️" , "❌" ,"✅"),
#     colours = c("#999999", "#f57dc1", NA, NA, NA),
#     name = "Study Events"
#   )

Experiment

Closing remarks, Other Relevant Work, Caveats