1

I have estimated a Kaplan-Meier with two group using this code:

test3 <- survfit(Surv(wave, con3) ~ sex, data = consult3)
ggsurvplot(test3, color = "#2E9FDF",
       risk.table = TRUE, risk.table.y.text.col = TRUE)

and even though it produces a KM, it looks very weird and does not show me 2 different survival curves for sex==1 or sex==2. Does anybody know what I might have done wrong? Thanks!!

1

Allan Cameron
  • 147,086
  • 7
  • 49
  • 87
  • Hi, interesting question, however you may want to make a reproducible example, please read: [how-to-make-a-great-r-reproducible-example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example/5963610#5963610) – jay.sf Sep 19 '20 at 11:47

1 Answers1

1

It's always better to include some sample data so we can see where the problem lies. However, let's see if we can create some data that will replicate your problem:

library(survival)
library(survminer)

set.seed(69)

consult3 <- data.frame(sex = rep(1:2, each = 50),
                       con3 = c(rbinom(50, 1, 0.2), rbinom(50, 1, 0.4)),
                       wave = sample(3, 100, TRUE))

Now, using your code, we can get a similar-looking result:

test3 <- survfit(Surv(wave, con3) ~ sex, data = consult3)

ggsurvplot(test3, risk.table = TRUE, color = "#2E9FDF",
           risk.table.y.text.col = TRUE)

As far as I can tell, the problem with this is that you have set a single colour aesthetic. The solution is to just remove this:

ggsurvplot(test3, risk.table = TRUE, risk.table.y.text.col = TRUE)

If you want control over the colour of the lines, use palette instead of color:

ggsurvplot(test3, palette = c("red", "forestgreen"), alpha = 0.5,
           risk.table = TRUE, risk.table.y.text.col = TRUE)

enter image description here Created on 2020-09-19 by the reprex package (v0.3.0)

Allan Cameron
  • 147,086
  • 7
  • 49
  • 87