是否可以将自定义表添加到survminer::gsurvplot()中

oyt4ldly  于 2022-12-25  发布在  其他
关注(0)|答案(2)|浏览(204)

我正在研究卡普兰迈耶图,想知道是否有可能附加一个自定义表的情节。类似于一个突出显示如下。

我看到,默认情况下,如果我选择risk.table = TRUE,则会得到下面的表,但我需要上面的表,我自定义了该表,但我想知道如何传递它

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()
  )
xzv2uavs

xzv2uavs1#

下面是一个完全可复制的示例。我们从加载所需的包和数据开始。创建原始csv的adae2 Dataframe 需要一些争论和猜测。您可能希望跳过此阶段,因为您已经将数据转换为所需的格式:

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))

现在我们创建模型和survplot,然后存储它:

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())

这就完成了我们的工作,现在我们需要创建一个ggplot表,并用它覆盖风险表,这相当复杂:

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))

但是,我们现在应该只需要做:

p1

lc8prwob

lc8prwob2#

adae2数据

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()

要追加的表

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,'(?=\\=).*(?<=\\,)'))

相关问题