Assigns factor levels to an identifying key in a tibble (often subject ID) by a second variable (often study duration), with the option to perform this sorting within groups. Most often used before a call to ggplot() + geom_swimlane()

order_swimlane(.data, id_var, order_by, order_within = NULL)

Arguments

.data

A tibble or data.frame

id_var

Row (often subject) ID

order_by

Variable to sort by, often time on study

order_within

Variable to sort within, often cohort

Value

A tibble with id_var as a releveled factor

Examples

patient_disposition %>%
  order_swimlane(subject, weeks_on_study, cohort)
#> # A tibble: 20 × 6
#>    subject weeks_on_study cohort   reason_off_study      prior_drug partial_re…¹
#>    <fct>            <dbl> <chr>    <chr>                 <chr>             <dbl>
#>  1 980129          15.0   Cohort B Withdrawal by subject Yes               10.8 
#>  2 986548          26.9   Cohort B Withdrawal by subject No                NA   
#>  3 223561          27.5   Cohort B Physician decision    Yes               26.1 
#>  4 751377          31.2   Cohort B Withdrawal by subject No                NA   
#>  5 297647          42.6   Cohort B Disease progression   Yes               NA   
#>  6 321235          64.7   Cohort B Adverse event         No                NA   
#>  7 226603          74.4   Cohort B Disease progression   No                NA   
#>  8 361221          78.7   Cohort B Completed             Yes               60.2 
#>  9 460588          79.6   Cohort B NA                    Yes               NA   
#> 10 158396           0.186 Cohort A Adverse event         Yes               NA   
#> 11 992253          22.8   Cohort A Adverse event         Yes               NA   
#> 12 828351          40.9   Cohort A Disease progression   Yes                8.82
#> 13 467205          52.5   Cohort A Disease progression   Yes               44.6 
#> 14 542555          64.9   Cohort A Disease progression   Yes               NA   
#> 15 339057          70.3   Cohort A Physician decision    Yes               35.7 
#> 16 690585          72.2   Cohort A Adverse event         Yes               52.2 
#> 17 465452          86.4   Cohort A NA                    No                67.3 
#> 18 337310          86.5   Cohort A Completed             No                NA   
#> 19 494306          87.6   Cohort A NA                    Yes                8.26
#> 20 482665          94.2   Cohort A Completed             No                NA   
#> # … with abbreviated variable name ¹​partial_response