在 R 图的图例中插入数学符号
Inserting math symbols in legends of R plots
我正在使用 survminer 生成具有 2 条生存曲线的生存图,一条针对在手术期间接受 4 个浓缩红细胞 (PRBC) 单位的患者,一条针对接受超过 4 个 PRBC 单位的患者。不幸的是,我无法使用 "expression" 或 "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"))
要在字符串中放置一个 unicode 字符,您可以使用要使用 \u
转义的符号的 unicode 编号。即对 ≥ 使用 \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"))
我正在使用 survminer 生成具有 2 条生存曲线的生存图,一条针对在手术期间接受 4 个浓缩红细胞 (PRBC) 单位的患者,一条针对接受超过 4 个 PRBC 单位的患者。不幸的是,我无法使用 "expression" 或 "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"))
要在字符串中放置一个 unicode 字符,您可以使用要使用 \u
转义的符号的 unicode 编号。即对 ≥ 使用 \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"))