We can also creat a swimmer plot using the ggplot2 package. We will here use the dataset created in the Data & Function page.
# Libraries
library(swimplot)
library(ggplot2)
library(tidyverse)swimdata$Prog[swimdata$Prog=="yes"]<-"Progression"
swimdata <- swimdata[-10,]
swimdata <- arrange(swimdata, survie)
swimdata$SUBJID <- factor(swimdata$SUBJID, levels = swimdata$SUBJID)
swimdata%>%ggplot(aes(SUBJID, survie)) + # Base axis
geom_bar(stat="identity", aes(fill=factor(Bestrep))) + # Bar plot. Colour by stage
geom_point(data=swimdata, # Use df.shapes to add reponse points
aes(SUBJID, survie, shape=Death), size=3) +
geom_point(data=swimdata, # Use df.shapes to add reponse points
aes(SUBJID, delpfs, shape=Prog), size=3)+
ylab("Time (in days)") +
xlab("ID") +
coord_flip()+
labs(fill="Bestrep")+
theme_classic()+
scale_shape_manual("Death", values = c(16,15,17))
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.