We build the following dataset: Data should be in the long format (each row is one time point per subject).
#Libraries
library(swimplot)
library(ggplot2)
library(tidyverse)#Creation of dataset
swimdata <- data.frame(
c("1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11"),
c(172, 220, 713, 451, 169, 1017, 1059, 744, 207, 403, 1081),
c("PD", "SD", "SD", "PD", "PD", "PR", "CR", "SD", "SD", "NE", "SD"),
c(1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0),
c(1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 0),
c("yes", "no", "no", "no", "no", "no", "no", "no", "yes", "no", "no"),
c("yes", "yes", "yes", "yes", "yes", "yes", "yes", NA, "yes", NA, NA),
c(127, 174, 256, 85, 54, 360, 420, 745, 209, 408, 1088)
)
colnames(swimdata) <- c("SUBJID","survie","Bestrep","dc","pfs","Death","Prog","delpfs") #Head of dataset
knitr::kable(head(swimdata,8),align = "l")| SUBJID | survie | Bestrep | dc | pfs | Death | Prog | delpfs |
|---|---|---|---|---|---|---|---|
| 1 | 172 | PD | 1 | 1 | yes | yes | 127 |
| 2 | 220 | SD | 0 | 1 | no | yes | 174 |
| 3 | 713 | SD | 0 | 1 | no | yes | 256 |
| 4 | 451 | PD | 0 | 1 | no | yes | 85 |
| 5 | 169 | PD | 0 | 1 | no | yes | 54 |
| 6 | 1017 | PR | 0 | 1 | no | yes | 360 |
| 7 | 1059 | CR | 0 | 1 | no | yes | 420 |
| 8 | 744 | SD | 0 | 0 | no | NA | 745 |
swimmer_plot(
df, a data frame
id = "id", column name for id
end = "end", column name with the bar lengths (or bar end positions if bars change colour)
start = "start", column name with the bar start positions (only required when there are gaps between sections of bars, or bars which do not start at zero)
col, color of the border of the bars
name_fill = NULL, a column name to map the bar fill
name_col = NULL, a column name to map the bar colour
name_alpha = NULL, a column name to map the bar transparency
increasing = TRUE, increasing order (Default is TRUE)
id_order = NULL, order of the bars by id, can input a column name to sort by, or the ids in order
stratify = FALSE, a list of column names to stratify by
base_size = 11, the base size for the plot, default is 11
identifiers = TRUE, binary to specify patient identifiers are included in the y axis (default is TRUE)
...
)
swimmer_points(
df_points, a data frame
id = "id", column name for id
time = "time", column name with the point locations
adj.y = 0, amount to adjust the point within the box vertically (default is 0, point is in the centre of each bar)
name_shape = NULL, a column name to map the point shape
name_col = NULL, a column name to map the point colour
name_size = NULL, a column name to map the point size
name_fill = NULL, a column name to map the point fill
name_stroke = NULL, a column name to map the
name_alpha = NULL, a column name to map the point transparency
...
)
swimmer_arrows(
df_arrows, a data frame
id = "id", column name for id
arrow_start = "end", column name with the arrow locations, default is “end”
cont = NULL, a column name including an indicator of which ids have an arrow
adj.y = 0, amount to adjust the line within the box vertically
name_col = NULL, a column name to map the arrow colour
arrow_positions = c(0.1, 1), a vector of the distance from the arrow start to end, default is c(0.1,1)
angle = 30, the angle of the arrow head in degrees
length = 0.1, a unit specifying the length of the arrow head (grom tip to bas in inches)
type = closed, one of “open” or “closed” indicating whether the arrow head should be a closed triangle
...
)
This document is a work by Emma Lafaurie (emma.lafaurie@inserm.fr) for the SBIM (Service de Biostatistique et Information Médicale) at Saint-Louis Hospital in Paris.
Based on the template of Yan Holtz.