5 When there is one column per event type
The gather_() function from the tidyr package can be used to change data from the wide to long format. When each event type has its only column with the exact time, the function only needs to be run once
library(tidyr)
data_time_points <- wide_example[,c('ID','AE','SAE','Death.date')]
points_long <- gather_(data=data_time_points,"point", "time",
gather_cols=c('AE','SAE','Death.date'),na.rm=T)
knitr::kable(points_long,align='c',row.names = F)| ID | point | time |
|---|---|---|
| ID:001 | AE | 5.0 |
| ID:002 | AE | 1.0 |
| ID:001 | SAE | 5.5 |
| ID:003 | SAE | 2.0 |
| ID:001 | Death.date | 6.0 |
| ID:003 | Death.date | 7.0 |
The points can now be added to the plot
plot+ swimmer_points(df=points_long,id='ID',name_shape = 'point',size=8)