将水平网格线添加到图形

时间:2019-05-14 08:04:45

标签: r ggplot2 gridlines

我继承了以下R脚本,我需要对其进行编辑,以便在生成的输出Kaplan Meiers折线图中添加水平网格线。

您如何做到的?

library(dplyr)
library(ggplot2)
library(survival)
library(survminer)
library(grid)
library(gridExtra)

pc <- dataset

fstat <- pc %>% mutate(fstatus = case_when(OUTCOMETYPE=="Revised" ~ 1,TRUE ~ 0))
pmpa <- fstat %>% select(PRIMARYPROCEDUREID,PRIMARYTOOUTCOMEYEARS,fstatus,OUTCOMETYPE)

if(nrow(pmpa) < 4){
    d <- pmpa %>% select(PRIMARYPROCEDUREID,PRIMARYTOOUTCOMEYEARS,OUTCOMETYPE) %>% mutate(INSUFFICIENTDATA = "Summary Results")
    h = head(d[,2:4])
    grid.table(h)
}else{
    fit <- survfit(Surv(PRIMARYTOOUTCOMEYEARS,fstatus)~1,data = pmpa) 
    ggsurv <- ggsurvplot(fit,
                         ylab="Patient Analysis",
                         xlab="Time (Years)",
                         break.time.by = 1,
                         xlim = c(0,max(fit$time)),
                         surv.scale = "percent",
                         legend.title = "Kaplan-Meier",
                         legend.labs = "",
                         risk.table = TRUE,
                         fontsize = 3,
                         font.tickslab = c(10, "plain"),
                         risk.table.y.text = FALSE,
                         fun = "event"
                         )

ggsurv$plot <- ggsurv$plot + theme(plot.title = element_text(hjust = 0.5, size=18)) 
ggsurv$table <- ggsurv$table + theme(plot.title = element_text(hjust = 0.5, size = 10))


ggsurv     
}

0 个答案:

没有答案