1

I am struggling to get a graph from my regression analysis with covariates

At the moment, I am able to get this survival graph with univariate analysis:

enter image description here

using these data:

    ID age sex mace mace_months_date_vs_date_sample  trop egfr dm smoke delta_mon3_baseline_to_m1
1  223  63   1    0                              46  4281   90  0     0                        NA
2   14  74   1    1                               6  7120   78  0     0                -20.485008
3   44  52   1    1                              30  2600   56  1     0                 -4.527664
4   32  66   1    0                              73  1710   90  1     0                        NA
5   52  49   1    0                              74  1740   71  0     1                 19.345222
6   50  54   1    0                              70 15300   90  0     1                        NA
7   57  58   1    0                              74  5010   68  0     1                        NA
8   20  56   1    1                               5    NA   75  0     1                        NA
9   17  44   1    0                              77   840   71  0     0                        NA
10  56  43   1    0                              70  1360   90  1     0                  9.432819
11  79  68   1    0                              45   776   90  0     0                        NA
12  35  47   1    0                              77    NA   83  0     0                        NA
13  22  46   1    0                              77  5330   88  0     1                        NA
14  29  73   0    0                              77    NA   51  0     0                 39.474195
15  26  66   1    0                              77   500   51  0     0                        NA
16  25  54   1    0                              73  1080   87  0     0                        NA
17  54  59   1    0                              71  1500   81  1     1                -45.001671
18  31  47   0    0                              72  6490   77  1     1                        NA
19  12  57   1    0                              71  6020   88  0     1                 84.053604
20  15  65   1    1                              43  6300   49  1     0                        NA
21  43  59   0    0                              74  2100   84  0     1                        NA
22  36  64   1    1                               5 15940   52  0     1                        NA
23  24  47   1    0                              77  2390   90  0     1                -25.490768
24  45  51   0    0                              73  3710   65  0     1                -28.535500
25  49  54   1    1                              28    NA   76  1     0                 64.658119
26  47  62   1    0                              69  1420   85  0     0                  8.131409
27  30  73   0    0                              68  3340   48  1     1                        NA
28  39  54   1    0                              74   990   77  0     0                        NA
29  21  46   1    0                              75  3600   87  0     1                 27.438457
30  16  57   1    0                              73   180   99  0     1                -30.582588
31  60  72   1    0                              76   470   62  0     0                        NA
32  55  47   1    0                              70    NA   90  0     1                        NA
33  37  81   1    0                              74    NA   99  1     1                        NA
34  27  28   1    0                              71  6440   90  0     1                 23.335308
35  13  53   1    0                              69  1970   87  1     1                -60.367096
36  19  66   1    0                              78  9320   59  0     0                        NA
37  42  38   1    0                              69  1800   69  0     1                  4.492434
38  28  76   1    0                              71    40   90  1     1                 15.378483
39 139  39   0    0                              58    NA   90  0     1                        NA
40  38  55   1    0                              78  3930   90  1     0                        NA
41  18  56   1    0                              69  6390   90  0     1                        NA
42  58  36   1    0                              76    NA   78  1     1                        NA
43  61  48   1    0                              76  4470   90  0     1                -26.374584
44  33  59   1    0                              69  2260   79  0     1                -13.386553
45 146  75   1    1                              21  1454   65  1     1                 14.503574
46  73  61   1    0                              44    11   90  0     0                        NA

And this code:

quantile <- df$delta_mon3_baseline_to_m1

fit <- survfit(Surv(mace_months_date_vs_date_sample, mace) ~ findInterval(quantile, quantile(quantile, na.rm = TRUE)[-5]), data = df)

#custom theme
custom_theme <- function(){
  theme_survminer() %+replace%
    theme(
      legend.background = element_rect(fill = "white", color = "black"),
      plot.title=element_text(hjust=0.9)
    )
}
 
#univariate survival curves
ggsurvplot(fit,
           pval = FALSE,
           ggtheme = custom_theme(), 
           censor = FALSE,
           legend = c(0.5, 0.2),
           legend.title = "Mon3, P=0.02",
           legend.labs = c("Quartile 1", "Quartile 2 HR", "Quartile 3 HR", "Quartile 4"),
           xlab = "Follow-up (months)",
           font.x = c(size = 15),
           ylab = "Survival from MACE",
           font.y = c(size = 15),
           break.y.by = 0.2,
           axes.offset = FALSE,
           palette = c("blue", "dark red", "green", "orange"))

I am trying to get the same graph but adding sex, age, trop, egfr, dm, and smoke as covariables.

I have tried this only with only sex and age:

fit2 <- survfit(Surv(mace_months_date_vs_date_sample, mace) ~ findInterval(quantile, quantile(quantile, na.rm = TRUE)[-5]) + sex + age, data = df)

ggsurvplot(fit2,
           pval = FALSE,
           ggtheme = custom_theme(), 
           censor = FALSE,
           legend = c(0.5, 0.2),
           legend.title = "Mon2, P=0.28",
           legend.labs = c("Quartile 1", "Quartile 2", "Quartile 3", "Quartile 4"),
           xlab = "Follow-up (months)",
           font.x = c(size = 15),
           ylab = "Survival from MACE",
           font.y = c(size = 15),
           break.y.by = 0.2,
           axes.offset = FALSE,
           palette = c("blue", "dark red", "green", "orange"))

But I got this feedback:

Error in ggsurvplot_df(d, fun = fun, color = color, palette = palette,  : 
  The length of legend.labs should be 56

Here is the console output:

structure(list(ID = c(223, 14, 44, 32, 52, 50, 57, 20, 17, 56, 
79, 35, 22, 29, 26, 25, 54, 31, 12, 15, 43, 36, 24, 45, 49, 47, 
30, 39, 21, 16, 60, 55, 37, 27, 13, 19, 42, 28, 139, 38, 18, 
58, 61, 33, 146, 73), age = c("63", "74", "52", "66", "49", "54", 
"58", "56", "44", "43", "68", "47", "46", "73", "66", "54", "59", 
"47", "57", "65", "59", "64", "47", "51", "54", "62", "73", "54", 
"46", "57", "72", "47", "81", "28", "53", "66", "38", "76", "39", 
"55", "56", "36", "48", "59", "75", "61"), sex = c(1, 1, 1, 1, 
1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 
1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1
), mace = c(0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
0, 0, 0, 0, 0, 0, 1, 0), mace_months_date_vs_date_sample = c(46, 
6, 30, 73, 74, 70, 74, 5, 77, 70, 45, 77, 77, 77, 77, 73, 71, 
72, 71, 43, 74, 5, 77, 73, 28, 69, 68, 74, 75, 73, 76, 70, 74, 
71, 69, 78, 69, 71, 58, 78, 69, 76, 76, 69, 21, 44), trop = c("4281", 
"7120", "2600", "1710", "1740", "15300", "5010", "NA", "840", 
"1360", "776", "NA", "5330", "NA", "500", "1080", "1500", "6490", 
"6020", "6300", "2100", "15940", "2390", "3710", "NA", "1420", 
"3340", "990", "3600", "180", "470", "NA", "NA", "6440", "1970", 
"9320", "1800", "40", "NA", "3930", "6390", "NA", "4470", "2260", 
"1454", "11"), egfr = c("90", "78", "56", "90", "71", "90", "68", 
"75", "71", "90", "90", "83", "88", "51", "51", "87", "81", "77", 
"88", "49", "84", "52", "90", "65", "76", "85", "48", "77", "87", 
"99", "62", "90", "99", "90", "87", "59", "69", "90", "90", "90", 
"90", "78", "90", "79", "65", "90"), dm = c("0", "0", "1", "1", 
"0", "0", "0", "0", "0", "1", "0", "0", "0", "0", "0", "0", "1", 
"1", "0", "1", "0", "0", "0", "0", "1", "0", "1", "0", "0", "0", 
"0", "0", "1", "0", "1", "0", "0", "1", "0", "1", "0", "1", "0", 
"0", "1", "0"), smoke = c("0", "0", "0", "0", "1", "1", "1", 
"1", "0", "0", "0", "0", "1", "0", "0", "0", "1", "1", "1", "0", 
"1", "1", "1", "1", "0", "0", "1", "0", "1", "1", "0", "1", "1", 
"1", "1", "0", "1", "1", "1", "0", "1", "1", "1", "1", "1", "0"
), delta_mon3_baseline_to_m1 = c(NA, -20.485008239746, -4.52766418457031, 
NA, 19.345222473145, NA, NA, NA, NA, 9.4328193664551, NA, NA, 
NA, 39.4741954803467, NA, NA, -45.0016708374024, NA, 84.0536041259771, 
NA, NA, NA, -25.4907684326172, -28.5354995727539, 64.6581192016601, 
8.13140869140629, NA, NA, 27.4384574890136, -30.5825881958007, 
NA, NA, NA, 23.3353080749512, -60.3670959472656, NA, 4.4924335479737, 
15.3784828186035, NA, NA, NA, NA, -26.374584197998, -13.386552810669, 
14.5035743713379, NA)), row.names = c(NA, -46L), class = c("tbl_df", 
"tbl", "data.frame"))
MaxStudent
  • 83
  • 6
  • could you please share your data using `dput()`? – Quinten Mar 25 '22 at 11:45
  • I have shared it, can you see it in the post ? – MaxStudent Mar 25 '22 at 11:48
  • have a look at this: https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – Claudio Paladini Mar 25 '22 at 11:53
  • 1
    Kaplan-Meier plots are usually stratified by a single categorical variable. If you stratify for more than 1, you will end up with a lot of lines, one for each combination (for example: "Quartile 1 male smok", "Quartile 1 male non-smok", "Quartile 1 female smok"...) - it quickly gets very crowded. (Your error message is saying that it's expecting 56 lines!) Also, I'm not sure how to include continuous variables such as `age` or `egfr`. Can you sketch an image of what your intended graph should look like? – Andrea M Mar 25 '22 at 13:14
  • @AndreaM you are right. The graph I would like should look like the same than the one I have presented: 4 curves according quartiles, but with ```age``` and ```sex``` added as covariables. – MaxStudent Mar 25 '22 at 13:58
  • If you add `sex`, there will be 8 curves: 4 quartiles among males, and 4 quartile among females. If you then add `age`, there will be 8 curves for each age! – Andrea M Mar 25 '22 at 14:06
  • ok. So there is something I'm missing here to answer my question how to produce survival curves according the quartiles and using these covariables.... I have to use Cox regression. – MaxStudent Mar 25 '22 at 14:09
  • @Quinten and Paladinic, I have updated the code and added the console output. – MaxStudent Mar 25 '22 at 14:22
  • @MaxStudent Cox regression would be fine as a way to model, but it won't help you plot. If you are wanting to plot four quantiles, ask yourself 'four quantiles of _what_?'. You can have one plot for each variable of interest and stitch them together using `patchwork`, but you cannot show the effects of multiple covariates on a single survival plot. – Allan Cameron Mar 25 '22 at 15:16
  • @AllanCameron, in fact, based on quartile of '''delta_mon3_baseline_to_m1''. Previous data not from me using STATA have created one Cox regression univariate analysis graph according quartile and another one but adding these covariates (a Cox regression multivariate analysis) again, according quartile of '''mon'''. Thank you very much. – MaxStudent Mar 25 '22 at 15:53

0 Answers0