Outline

Load data

Month= Days/30.4375

Build Data Structure

1 GGPlot

Generate multiple label

1.1 cohort

#order the plot data

t<- cartar%>% arrange(Cohort, desc(tos)) %>% mutate(row = row_number())
t$num <- 1:nrow(t)

p11 <- ggplot(t, aes(x=reorder(Subject_ID,-num), y=tos, fill=Cohort)) +
       geom_bar(stat="identity", position=position_dodge(0.7), width=0.4)+
      scale_fill_brewer(palette = "Pastel1") +
       coord_flip()+
       geom_point(data=carta3, aes(Subject_ID, dosem))  +
       labs(fill="Cohort", colour="",  x="Dummy ID",
       y="Months") +
       theme_minimal() + theme(legend.position="right", legend.justification=c(0,1))+
       #theme(legend.justification = "left")+
       guides(fill=guide_legend("Cohort")) 
p11

#Extract Label
ggp_l1_s1<-get_legend(p11)

1.2 Ongoing

o <- filter (t, cont=="Y")
p12 <- p11+ 
  geom_point(data=o,  aes(Subject_ID, tos1, shape=`Relapse.or.Censoring`), size=5)+ 
  scale_shape_manual(values=c( "\u2192"))+labs(shape="Ongoing") +
  guides(fill="none" )+  
  theme(legend.position="right", legend.justification=c(0,1),
        legend.title=element_blank()) #Remove legend Label
   # theme(legend.justification = "right")
p12

#Extract Label
ggp_l1_s2<-get_legend(p12)

1.3 Response

t1 <-  ggplot(t, aes(x=reorder(Subject_ID,-num), y=tos, fill=Cohort)) +
       geom_bar(stat="identity", position=position_dodge(0.7), width=0.35)+
       coord_flip()+
      scale_fill_brewer(palette = "Pastel1") +
       geom_point(data=carta3, aes(Subject_ID, rm, color=factor(Response)), shape=18, size=5)  +
       labs(fill="Cohort", colour="Response",  x="Dummy ID",
       y="Months") +
       theme_bw()  + guides(fill="none")+
       scale_color_manual( breaks = c("Complete Response", "Partial Response", "Stable Disease", "Progressive Disease"), 
                           values = c('#4c8045', '#e9cb95', '#1e59d0','#e3716e'),
                           labels = c("Complete Response", "Partial Response", "Stable Disease", "Progressive Disease"))+
       theme(panel.grid.minor=element_blank(),
       panel.grid.major=element_blank()) + theme(legend.position="right", legend.justification=c(0,1))
     #theme(legend.justification = "left")
t1

ggp_l1_s3<-get_legend(t1)

1.4 Main graph

n1 <-  ggplot(t, aes(x= reorder(Subject_ID, -num), y=tos, fill=Cohort)) +
       geom_bar(stat="identity", position=position_dodge(0.7), width=0.5)+        scale_fill_brewer(palette = "Pastel1") +
       coord_flip()+
       geom_point(data=carta3, aes(Subject_ID, rm, color=factor(Response)), shape=18, size=5)  +
       geom_point(data=carta3, aes(Subject_ID, dosem), shape=16)+
       labs(fill="Cohort", colour="Response",  x="Dummy ID",
       y="Months") +
       scale_y_continuous(breaks=c(0,2,4,6,8,10))+
       theme_bw()  + theme(legend.position = "none")+
       scale_color_manual( breaks = c("Complete Response", "Partial Response", "Stable Disease", "Progressive Disease"), 
                           values = c('#4c8045', '#e9cb95', '#1e59d0','#e3716e'),
                           labels = c("Complete Response", "Partial Response", "Stable Disease", "Progressive Disease"))+
       theme(panel.grid.minor=element_blank(),
       panel.grid.major=element_blank()) 

colnames(t)[37]<- "Relapse/Censoring"

n12 <- n1+geom_point(data=o,
                     aes(Subject_ID,  tos1, shape=`Relapse.or.Censoring`),size=6)+
       scale_shape_manual(values=c( "\u2192"))+
       labs(caption="Note: This is a dummy data sample of a Swimmer plot .
      ")+
       theme(plot.caption = element_text(hjust = 0,size=8))
n12

2 Final Plot

Plot_grid

a<- plot_grid(ggp_l1_s1,
              ggp_l1_s3,
              ggp_l1_s2,
              align="h" , ncol=1)


b<- plot_grid(n12,a, ncol=2,  rel_widths = c(4.1, 1))
## Warning: Removed 1 rows containing missing values (`geom_point()`).
b

Save PDF

#cairo_pdf(file=paste0("location"), width = 10, height = 4)
#b
#dev.off()

Happy Coding!