2

我正在使用 survminer 生成具有 2 条生存曲线的生存曲线,一条用于在手术期间接受 4 个包装红细胞 (PRBC) 单位的患者,另一种用于接受超过 4 个 PRBC 单位的患者。不幸的是,我无法使用“表达式”或“bquote”函数将正确的“<=”符号插入到图例中。

我已经阅读了有关此主题的先前帖子,但是我能够使用 expression() 和 bquote() 找到的指导似乎并没有正常工作。

library(survival)
library(coxed)
library(survminer)

simdata <- sim.survdata(N=300, T=100, num.data.frames=1, xvars = 1)

d <- simdata$data

d$Xfactor <- ifelse(d$X <= 0.3, 1, 0)


# the code chunks below do not seem to work because of the legends

ggsurvplot(
  fit = survfit(Surv(d$y, event = d$failed) ~ d$Xfactor, data = d), 
  xlab = "Years", 
  ylab = "Overall survival probability",
  main = "Overall survival",
  legend.labs = c(bquote(<= ~ "4 Units"),"> 4 Units"))

ggsurvplot(
  fit = survfit(Surv(d$y, event = d$failed) ~ d$Xfactor, data = d), 
  xlab = "Years", 
  ylab = "Overall survival probability",
  main = "Overall survival",
  legend.labs = c(bquote("" ~ <= ~ "4 Units"),"> 4 Units"))

ggsurvplot(
  fit = survfit(Surv(d$y, event = d$failed) ~ d$Xfactor, data = d), 
  xlab = "Years", 
  ylab = "Overall survival probability",
  main = "Overall survival",
  legend.labs = c(expression("",<=,"4 Units"),"> 4 Units"))

ggsurvplot(
  fit = survfit(Surv(d$y, event = d$failed) ~ d$Xfactor, data = d), 
  xlab = "Years", 
  ylab = "Overall survival probability",
  main = "Overall survival",
  legend.labs = c(expression(<=,"4 Units"),"> 4 Units"))

ggsurvplot(
  fit = survfit(Surv(d$y, event = d$failed) ~ d$Xfactor, data = d), 
  xlab = "Years", 
  ylab = "Overall survival probability",
  main = "Overall survival",
  legend.labs = c(expression(<= "4 Units"),"> 4 Units"))



4

1 回答 1

1

要将 unicode 字符放在字符串中,您可以使用 unicode 数字作为要转义的符号\u。那就是使用\u2265≥ 和\u2264≤。

ggsurvplot(
  fit = survfit(Surv(d$y, event = d$failed) ~ d$Xfactor, data = d), 
  xlab = "Years", 
  ylab = "Overall survival probability",
  main = "Overall survival",
  legend.labs = c("\u2264 4 Units","> 4 Units"))

在此处输入图像描述

于 2020-03-06T20:39:03.360 回答