Skip to contents
# Create a sample data frame using dates
set.seed(42)
n_patients <- 15
treatment_start_dates <- as.Date("2022-01-01") + sample(1:60, n_patients, replace = TRUE)
treatment_durations_days <- sample(60:1000, n_patients, replace = TRUE)

melanoma_study <- data.frame(
  Subject_ID = paste("P", 101:(100 + n_patients), sep = ""),
  Start_Date = treatment_start_dates,
  End_Date = treatment_start_dates + treatment_durations_days,
  Best_Response = factor(sample(c("Complete Response", "Partial Response", "Stable Disease", "Progressive Disease"),
                           n_patients, replace = TRUE, prob = c(0.2, 0.4, 0.3, 0.1))),
  Survival_Days = treatment_durations_days + sample(0:300, n_patients, replace = TRUE)
)

head(melanoma_study)
#>   Subject_ID Start_Date   End_Date       Best_Response Survival_Days
#> 1       P101 2022-02-19 2024-01-01      Stable Disease           826
#> 2       P102 2022-02-07 2023-09-21    Partial Response           699
#> 3       P103 2022-01-02 2023-04-16   Complete Response           665
#> 4       P104 2022-01-26 2024-08-24    Partial Response           944
#> 5       P105 2022-01-11 2024-08-06    Partial Response          1163
#> 6       P106 2022-02-06 2024-09-21 Progressive Disease          1172
# This code simulates how the jamovi module would be called in an R environment.
# You would need the ClinicoPathDescriptives package installed.

# Load the library
library(ClinicoPathDescriptives)
#> Registered S3 method overwritten by 'future':
#>   method               from      
#>   all.equal.connection parallelly
#> Warning: replacing previous import 'dplyr::select' by 'jmvcore::select' when
#> loading 'ClinicoPathDescriptives'

# Run the swimmer plot analysis using the new, correct arguments
results <- swimmerplot(
    data = melanoma_study,
    patientID = "Subject_ID",
    start = "Start_Date",
    end = "End_Date",
    event = "Best_Response",
    sortVariable = "Survival_Days",
    timetype = "datetime",
    timetypeoutput = "months",
    referenceLines = "custom",
    customReferenceTime = 24
)

# The result is a plot image.
print(results$plot)