0

I would to overlay two different survival curves on same plot, for example OS et PFS (here false results).


N pt.   OS.        OS_Time_(years).    PFS.     PFS_Time_(years).
__________________________________________________________________
1.      1            12                  0          12
2.      0            10                  1          8
3.      0            14                  0          14
4.      0            10                  0          10
5.      1            11                  1          8
6.      1            16                  1          6
7.      0            11                  1          4
8.      0            12                  1          10
9.      1            9                   0          9
10      1            10                  1          9
__________________________________________________________ 

First, I import my dataset:

library(readxl)
testR <- read_excel("~/test.xlsx")
View(testR)

Then, I created survfit for both OS and PFS:

OS<-survfit(Surv(OS_t,OS)~1, data=test)
PFS<-survfit(Surv(PFS_t,PFS)~1, data=test)

And finally, I can plot each one thanks to:

plot(OS) 
plot(PFS)

for example (or ggplot2...).

Here my question, if I want to overlay the 2 ones on same graph, how can I do?

I tried multipleplot or

ggplot(testR, aes(x)) +                    # basic graphical object
  geom_line(aes(y=y1), colour="red") +  # first layer
  geom_line(aes(y=y2), colour="green")  # second layer

But it didn't work (but I'm not sure to use it correctly). Can someone help me, please ?

Thanks a lot

Here is my code for Data sample:

test <- structure(list(ID = c(NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 1, 2, 3, 4, 5, 6, 7, 8, 9), 
                       Sex = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1), 
                       Tabac = c(2, 0, 1, 1, 0, 0, 2, 0, 0, 0, 1, 1, 1, 0, 2, 0, 1, 1, 1), 
                       Bmi = c(20, 37, 37, 25, 28, 38, 16, 27, 26, 28, 15, 36, 20, 17, 28, 37, 27, 26, 18),
                       Age = c(75, 56, 45, 65, 76, 34, 87, 43, 67, 90, 56, 37, 84, 45, 80, 87, 90, 65, 23), c(0, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0), 
                       OS_times = c(2, 4, 4, 2, 3, 5, 5, 3, 2, 2, 4, 1, 3, 2, 4, 3, 4, 3, 2), 
                       OS = c(0, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0), 
                       PFS_time = c(1, 2, 1, 1, 3, 4, 3, 1, 2, 2, 4, 1, 2, 2, 2, 3, 4, 3, 2), 
                       PFS = c(1, 1, 1, 1, 0, 1, 1, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0)), 
                  .Names = c("ID", "Sex", "Tabac", "Bmi", "Age", "LN", "OS_times", "OS", "PFS_time", "PFS"), 
                  class = c("tbl_df", "tbl", "data.frame"), 
                  row.names = c(NA, -19L))
KoenV
  • 4,113
  • 2
  • 23
  • 38
Alexandre
  • 1
  • 5
  • Please, add some data with dput() so we can reproduce your attempts. Look at [How to make a great R reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) – Marcelo Apr 14 '17 at 05:20

1 Answers1

1

You may use the ggsurv function from the GGally package in the following way. Combine both groups of variables in a data frame and add a "type" column. Later in the call to the plot, you refer to the type.

I used your data structure and named it "test". Afterwards, I transformed it to a data frame with the name "testdf".

library(GGally)

testdf <- data.frame(test)
OS_PFS1 <- data.frame(life = testdf$OS, life_times = testdf$OS_times, type= "OS")
OS_PFS2 <- data.frame(life = testdf$PFS, life_times = testdf$PFS_time, type= "PFS")
OS_PFS <- rbind(OS_PFS1, OS_PFS2)

sf.OS_PFS <- survfit(Surv(life_times, life) ~ type, data = OS_PFS)
ggsurv(sf.OS_PFS)

if you want the confidence intervals shown:

ggsurv(sf.OS_PFS, CI = TRUE)

Please let me know whether this is what you want.

KoenV
  • 4,113
  • 2
  • 23
  • 38