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)
<- wide_example[,c('ID','AE','SAE','Death.date')]
data_time_points <- gather_(data=data_time_points,"point", "time",
points_long gather_cols=c('AE','SAE','Death.date'),na.rm=T)
::kable(points_long,align='c',row.names = F) knitr
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
+ swimmer_points(df=points_long,id='ID',name_shape = 'point',size=8) plot