Home > Enterprise >  is it possible to add a custom table into survminer::ggsurvplot()
is it possible to add a custom table into survminer::ggsurvplot()

Time:12-21

I am working on the kaplan meier plot and would like to know if it is possible to attach a custom table to the plot. similar to the one highlighted below.

enter image description here

I see that by default, if i select the risk.table = TRUE, then i get the below table but i want the one like above, which i customized but i want to know how to pass it

enter image description here

survminer::ggsurvplot(km1, data = adae2, risk.table = TRUE,  
                                legend='none',
                                title=paste0('SOC: ', {{aesoc}}),
                                legend.labs = c("Placebo", "Xanomeline High Dose", 'Xanomeline Low Dose'),
                                ggtheme=theme_classic(),
                                tables.theme=theme_classic()
  ) 

CodePudding user response:

Here's a fully reproducible example. We start by loading the packages and data we need. Creating the adae2 dataframe the raw csv took a bit of wrangling and guesswork. You will probably want to skip this stage since you have already wrangled the data into the format you want:

library(tidyverse)
library(lubridate)
library(survminer)
library(survival)

aesoc <- 'GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS'

adae <- read.csv(paste0('https://raw.githubusercontent.com/jagadishkatam/',
                        'phuse/main/adae.csv')) 

adae1 <- adae %>%
  filter(AESOC == aesoc) %>%
  rename(trt01a = TRTA, usubjid = USUBJID) %>%
  arrange(trt01a, usubjid) %>%
  group_by(usubjid) %>%
  summarize(aval = min(ASTDY[ASTDY >= 0]),
            trt01a = first(trt01a),
            aesoc = aesoc) %>%
  arrange(trt01a, usubjid) 

adae2 <- adae1 %>%
  bind_rows(adae %>%
              filter(AESOC != aesoc) %>%
              rename(trt01a = TRTA, usubjid = USUBJID) %>%
              arrange(trt01a, usubjid) %>%
              group_by(usubjid) %>%
              summarize(aval = NA_real_,
                        trt01a = first(trt01a),
                        aesoc = aesoc) %>%
              arrange(trt01a, usubjid)) %>%
  mutate(cnsr = ifelse(is.na(aval), 0, 1))

Now we create the model and the survplot, then store it:

km1 <- survfit(Surv(aval, cnsr) ~ trt01a   aesoc, data = adae2)

p1 <- ggsurvplot(km1, data = adae2, risk.table = TRUE,  
                 legend='none',
                 title=paste0('SOC: ', {{aesoc}}),
                 legend.labs = c("Placebo", 
                                 "Xanomeline High Dose", 
                                 'Xanomeline Low Dose'),
                 ggtheme = theme_classic()) 

This takes us as far as you had got. Now we need to create a ggplot table and use it to over-write the risk table. This is fairly involved:

tabdata <- summary(km1)$table %>%
  as.data.frame() %>%
  tibble::rownames_to_column('grp') %>%
  mutate(grp = unlist(str_extract_all(grp,'(?<=\\=).*(?=\\,)'))) %>%
  pivot_longer(-grp) %>%
  mutate(value = as.character(round(value, 3))) %>%
  add_row(grp = "Placebo", name = "", value = "Placebo", .before = 1) %>%
  add_row(grp = "Xanomeline Low Dose", name = "", 
          value = "Xanomeline Low Dose", .before = 1) %>% 
  add_row(grp = "Xanomeline High Dose", name = "", 
          value = "Xanomeline High Dose", .before = 1) %>%
  mutate(name = factor(name, unique(name)),
         grp = factor(grp, unique(grp)))


p1$table <- ggplot(tabdata, aes(as.numeric(name), grp))  
  geom_text(aes(label = value), size = 4, hjust = 1)  
  labs(x = NULL, y = NULL)  
  scale_x_continuous(position = "top", limits = c(-2, 10),
                     breaks = 1:10, labels = levels(tabdata$name))  
  theme_minimal(base_size = 12)  
  theme(panel.grid = element_blank(),
        panel.border = element_rect(fill = NA),
        axis.text.y = element_blank(),
        axis.text.x.top = element_text(hjust = 1))

However, we should now only need to do:

p1

enter image description here

CodePudding user response:

adae2 data

structure(list(usubjid = c("01-701-1015", "01-701-1130", "01-701-1363", 
"01-703-1100", "01-704-1164", "01-708-1286", "01-708-1296", "01-708-1316", 
"01-709-1088", "01-709-1259", "01-709-1306", "01-709-1312", "01-710-1060", 
"01-710-1077", "01-710-1264", "01-713-1179", "01-713-1256", "01-713-1269", 
"01-717-1344", "01-718-1150", "01-718-1355", "01-701-1023", "01-701-1047", 
"01-701-1118", "01-701-1153", "01-701-1203", "01-701-1234", "01-701-1345", 
"01-701-1387", "01-701-1392", "01-701-1415", "01-701-1440", "01-703-1042", 
"01-703-1096", "01-703-1175", "01-703-1210", "01-703-1299", "01-704-1010", 
"01-704-1127", "01-704-1233", "01-704-1260", "01-704-1351", "01-704-1388", 
"01-704-1435", "01-704-1445", "01-705-1018", "01-705-1059", "01-705-1186", 
"01-705-1282", "01-705-1349", "01-706-1041", "01-707-1206", "01-708-1087", 
"01-708-1158", "01-708-1171", "01-708-1253", "01-708-1342", "01-708-1378", 
"01-709-1001", "01-709-1301", "01-709-1339", "01-710-1027", "01-710-1078", 
"01-710-1083", "01-710-1183", "01-710-1271", "01-710-1314", "01-710-1315", 
"01-710-1368", "01-711-1036", "01-714-1035", "01-714-1375", "01-715-1155", 
"01-715-1207", "01-715-1397", "01-716-1024", "01-716-1026", "01-716-1044", 
"01-716-1108", "01-716-1160", "01-716-1177", "01-716-1308", "01-716-1441", 
"01-717-1201", "01-718-1139", "01-718-1172"), aesoc = c("GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", 
"GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", "GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", 
"GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", "GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", 
"GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", "GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", 
"GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", "GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", 
"GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", "GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", 
"GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", "GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", 
"GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", "GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", 
"GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", "GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", 
"GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", "GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", 
"GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", "GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", 
"GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", "GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", 
"GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", "GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", 
"GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", "GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", 
"GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", "GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", 
"GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", "GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", 
"GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", "GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", 
"GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", "GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", 
"GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", "GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", 
"GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", "GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", 
"GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", "GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", 
"GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", "GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", 
"GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", "GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", 
"GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", "GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", 
"GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", "GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", 
"GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", "GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", 
"GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", "GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", 
"GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", "GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", 
"GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", "GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", 
"GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", "GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", 
"GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", "GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", 
"GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", "GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", 
"GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", "GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", 
"GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", "GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", 
"GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", "GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", 
"GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", "GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", 
"GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", "GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", 
"GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", "GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", 
"GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", "GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", 
"GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", "GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", 
"GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", "GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", 
"GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", "GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", 
"GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", "GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", 
"GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS"), astdy = c(2, 
23, 48, 24, 139, 3, 83, 177, 27, 78, 77, 28, 21, 26, 109, 28, 
42, 7, 22, 56, 59, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA), inb = c(TRUE, TRUE, TRUE, TRUE, TRUE, 
TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, 
TRUE, TRUE, TRUE, TRUE, TRUE, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA), trt01a = c("Placebo", "Placebo", 
"Placebo", "Placebo", "Placebo", "Placebo", "Placebo", "Placebo", 
"Placebo", "Placebo", "Placebo", "Placebo", "Placebo", "Placebo", 
"Placebo", "Placebo", "Placebo", "Placebo", "Placebo", "Placebo", 
"Placebo", "Placebo", "Placebo", "Placebo", "Placebo", "Placebo", 
"Placebo", "Placebo", "Placebo", "Placebo", "Placebo", "Placebo", 
"Placebo", "Placebo", "Placebo", "Placebo", "Placebo", "Placebo", 
"Placebo", "Placebo", "Placebo", "Placebo", "Placebo", "Placebo", 
"Placebo", "Placebo", "Placebo", "Placebo", "Placebo", "Placebo", 
"Placebo", "Placebo", "Placebo", "Placebo", "Placebo", "Placebo", 
"Placebo", "Placebo", "Placebo", "Placebo", "Placebo", "Placebo", 
"Placebo", "Placebo", "Placebo", "Placebo", "Placebo", "Placebo", 
"Placebo", "Placebo", "Placebo", "Placebo", "Placebo", "Placebo", 
"Placebo", "Placebo", "Placebo", "Placebo", "Placebo", "Placebo", 
"Placebo", "Placebo", "Placebo", "Placebo", "Placebo", "Placebo"
), trt01an = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
0, 0, 0, 0, 0, 0, 0), ina = c(TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, 
TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, 
TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, 
TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, 
TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, 
TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, 
TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, 
TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, 
TRUE, TRUE, TRUE), aval = c(2, 23, 48, 24, 139, 3, 83, 177, 27, 
78, 77, 28, 21, 26, 109, 28, 42, 7, 22, 56, 59, 1, 1, 1, 1, 1, 
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1), cnsr = c(1, 
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
0)), class = c("grouped_df", "tbl_df", "tbl", "data.frame"), row.names = c(NA, 
-86L), groups = structure(list(usubjid = c("01-701-1015", "01-701-1023", 
"01-701-1047", "01-701-1118", "01-701-1130", "01-701-1153", "01-701-1203", 
"01-701-1234", "01-701-1345", "01-701-1363", "01-701-1387", "01-701-1392", 
"01-701-1415", "01-701-1440", "01-703-1042", "01-703-1096", "01-703-1100", 
"01-703-1175", "01-703-1210", "01-703-1299", "01-704-1010", "01-704-1127", 
"01-704-1164", "01-704-1233", "01-704-1260", "01-704-1351", "01-704-1388", 
"01-704-1435", "01-704-1445", "01-705-1018", "01-705-1059", "01-705-1186", 
"01-705-1282", "01-705-1349", "01-706-1041", "01-707-1206", "01-708-1087", 
"01-708-1158", "01-708-1171", "01-708-1253", "01-708-1286", "01-708-1296", 
"01-708-1316", "01-708-1342", "01-708-1378", "01-709-1001", "01-709-1088", 
"01-709-1259", "01-709-1301", "01-709-1306", "01-709-1312", "01-709-1339", 
"01-710-1027", "01-710-1060", "01-710-1077", "01-710-1078", "01-710-1083", 
"01-710-1183", "01-710-1264", "01-710-1271", "01-710-1314", "01-710-1315", 
"01-710-1368", "01-711-1036", "01-713-1179", "01-713-1256", "01-713-1269", 
"01-714-1035", "01-714-1375", "01-715-1155", "01-715-1207", "01-715-1397", 
"01-716-1024", "01-716-1026", "01-716-1044", "01-716-1108", "01-716-1160", 
"01-716-1177", "01-716-1308", "01-716-1441", "01-717-1201", "01-717-1344", 
"01-718-1139", "01-718-1150", "01-718-1172", "01-718-1355"), 
    aesoc = c("GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", 
    "GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", "GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", 
    "GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", "GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", 
    "GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", "GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", 
    "GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", "GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", 
    "GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", "GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", 
    "GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", "GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", 
    "GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", "GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", 
    "GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", "GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", 
    "GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", "GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", 
    "GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", "GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", 
    "GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", "GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", 
    "GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", "GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", 
    "GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", "GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", 
    "GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", "GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", 
    "GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", "GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", 
    "GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", "GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", 
    "GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", "GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", 
    "GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", "GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", 
    "GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", "GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", 
    "GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", "GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", 
    "GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", "GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", 
    "GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", "GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", 
    "GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", "GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", 
    "GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", "GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", 
    "GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", "GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", 
    "GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", "GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", 
    "GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", "GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", 
    "GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", "GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", 
    "GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", "GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", 
    "GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", "GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", 
    "GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", "GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", 
    "GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", "GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", 
    "GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", "GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", 
    "GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", "GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", 
    "GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", "GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", 
    "GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", "GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", 
    "GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", "GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", 
    "GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", "GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", 
    "GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", "GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", 
    "GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", "GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", 
    "GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", "GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", 
    "GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", "GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS", 
    "GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS"), 
    .rows = structure(list(1L, 22L, 23L, 24L, 2L, 25L, 26L, 27L, 
        28L, 3L, 29L, 30L, 31L, 32L, 33L, 34L, 4L, 35L, 36L, 
        37L, 38L, 39L, 5L, 40L, 41L, 42L, 43L, 44L, 45L, 46L, 
        47L, 48L, 49L, 50L, 51L, 52L, 53L, 54L, 55L, 56L, 6L, 
        7L, 8L, 57L, 58L, 59L, 9L, 10L, 60L, 11L, 12L, 61L, 62L, 
        13L, 14L, 63L, 64L, 65L, 15L, 66L, 67L, 68L, 69L, 70L, 
        16L, 17L, 18L, 71L, 72L, 73L, 74L, 75L, 76L, 77L, 78L, 
        79L, 80L, 81L, 82L, 83L, 84L, 19L, 85L, 20L, 86L, 21L), ptype = integer(0), class = c("vctrs_list_of", 
    "vctrs_vctr", "list"))), class = c("tbl_df", "tbl", "data.frame"
), row.names = c(NA, -86L), .drop = TRUE))
km1 <- survival::survfit(survival::Surv(aval,cnsr)~trt01a aesoc, data=adae2)

survminer::ggsurvplot(km1, data = adae2, risk.table = FALSE,  
                                legend='none',
                                title=paste0('SOC: ', aesoc),
                                ggtheme=theme_classic(),
                                tables.theme=theme_classic()

table to append

newtable1 <- summary(survival::survfit(survival::Surv(aval,cnsr)~trt01a aesoc, data=adae2))$table
  newtable2 <- tibble::rownames_to_column(as.data.frame(newtable1), 'grp') %>% mutate(grp=str_extract_all(grp,'(?=\\=).*(?<=\\,)'))
  •  Tags:  
  • r
  • Related