rggplot2survival-analysissurvminer

How to add labels to multiple plots using ggsurvplot and arrange_ggsurvplots in r


I am trying to create a figure in R that includes multiple kaplan-meier curves, and label each kaplan-meier plot (i.e. "A", "B", "C"). Reading previous recommendations, they recommend using labs(tag="A") for each plot.

However, when I try this I get the error message " non-numeric argument to binary operator." Please help advise me. I used a working example from the existing lung dataset from survminer below.

library('survminer');
require('survival');

lung.ecog0 <- lung[lung$ph.ecog==0,];
lung.ecog1 <- lung[lung$ph.ecog==1,];
lung.ecog2 <- lung[lung$ph.ecog==2,];

fit.ecog0 <- survfit(Surv(time, status)~sex, data=lung.ecog0);
fit.ecog1 <- survfit(Surv(time, status)~sex, data=lung.ecog1);
fit.ecog2 <- survfit(Surv(time, status)~sex, data=lung.ecog2);

km.ecog0 <- ggsurvplot(fit.ecog0);
km.ecog1 <- ggsurvplot(fit.ecog1);
km.ecog2 <- ggsurvplot(fit.ecog2);

km.plot.list<-as.list(c(km.ecog0, km.ecog1, km.ecog2));

km.plot.list[[1]]$plot <- km.plot.list[[1]]$plot + labs(tag='A');
km.plot.list[[1]]$plot <- km.plot.list[[1]]$plot + labs(tag='B');
km.plot.list[[1]]$plot <- km.plot.list[[1]]$plot + labs(tag='C');

arrange_ggsurvplots(km.plot.list, print=TRUE, ncol=3, nrow=1);

Help is greatly appreciated!


Solution

  • There are a couple of problems here. Firstly, create the list like this:

    km.plot.list <- list(km.ecog0, km.ecog1, km.ecog2);
    

    Secondly, don't overwrite each list member (you have km.plot.list[[1]] each time)

    km.plot.list[[1]]$plot <- km.plot.list[[1]]$plot + labs(tag='A');
    km.plot.list[[2]]$plot <- km.plot.list[[2]]$plot + labs(tag='B');
    km.plot.list[[3]]$plot <- km.plot.list[[3]]$plot + labs(tag='C');
    

    So now we have

    arrange_ggsurvplots(km.plot.list, print=TRUE, ncol=3, nrow=1);
    

    enter image description here