[英]How can one add a ">" symbol while producing survival curves in R?
有沒有辦法在ggsurvplot中添加大於符號“>”? 在圖例中?
這是我針對此問題的示例數據集和代碼:
structure(list(X = 1:26, OS = c(59, 115, 156, 421, 431, 448, 464,
475, 477, 563, 638, 744, 769, 770, 803, 855, 1040, 1106, 1129, 1206,
1227, 268, 329, 353, 365, 377), OS_event = c(1, 1, 1, 0, 1, 0, 1, 1,
0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0), age = c("> 50
years", "> 50 years", "> 50 years", "> 50 years", "> 50 years", "> 50
years", "> 50 years", "> 50 years", "> 50 years", "> 50 years", "> 50
years", "> 50 years", "> 50 years", "< 50 years", "< 50 years", "< 50
years", "< 50 years", "< 50 years", "< 50 years", "< 50 years", "< 50
years", "< 50 years", "< 50 years", "< 50 years", "< 50 years", "< 50
years"), resid.ds = c(2L, 2L, 2L, 2L, 2L, 1L, 2L, 2L, 2L, 1L, 1L, 1L,
2L, 2L, 1L, 1L, 2L, 1L, 1L, 2L, 1L, 2L, 2L, 1L, 2L, 1L), rx = c(1L,
1L, 1L, 2L, 1L, 1L, 2L, 2L, 1L, 2L, 1L, 2L, 2L, 2L, 1L, 1L, 1L, 1L,
2L, 2L, 2L, 1L, 1L, 2L, 2L, 2L), ecog.ps = c(1L, 1L, 2L, 1L, 1L, 2L,
2L, 2L, 1L, 2L, 2L, 1L, 2L, 1L, 1L, 2L, 2L, 1L, 1L, 1L, 2L, 2L, 1L,
2L, 1L, 1L)), row.names = c(NA,
-26L), class = "data.frame")
Load data and packages
pacman::p_load(pacman, party, rio, tidyverse)
library(survival)
library(survminer)
library(ggtext)
ovarian <- read.csv("~/Desktop/ovarian.csv", stringsAsFactors = FALSE)
ovarian$OS = as.numeric(ovarian$OS) ovarian$OS_event =
as.numeric(ovarian$OS_event)
# Run KM plot:
ggsurvplot(survfit(Surv(OS, OS_event) ~ ovarian$age,
data = ovarian),
risk.table = TRUE,
pval = TRUE,
pval.coord = c(72,0.8),
legend.labs = c("< 55 years", "> 55 years"),
title = " OS by binarised median age",
legend = "right",
legend.title = "Binarised median age",
break.x.by=24,
palette = c("red", "blue"),
xlab="Time (Months)",
xlim=c(0,96))
但是,這會產生以下錯誤:
錯誤:gridtext 遇到了尚不支持的標記:
目前只支持非常有限數量的標簽。
值得回顧一下實際發生的事情。 ggtext
函數嘗試使用標簽解析標簽,但不支持ggtext
標簽 ( >
)。 所以我們需要一些方法來轉義標簽。 我找不到記錄的方式。
這是一個黑客攻擊的一位,但我添加了一個零寬度空間Unicode字符( \
前) >
打破標簽:
ggsurvplot(survfit(Surv(OS, OS_event) ~ ovarian$age,
data = ovarian),
risk.table = TRUE,
pval = TRUE,
pval.coord = c(72,0.8),
legend.labs = c("< 55 years", "\u200B> 55 years"),
title = " OS by binarised median age",
legend = "right",
legend.title = "Binarised median age",
break.x.by=24,
palette = c("red", "blue"),
xlab="Time (Months)",
xlim=c(0,96))
順便說一句,您不必手動將標題居中。 您可以將以下參數添加到ggsurvplot
:
ggtheme = theme_survminer() + theme(plot.title = element_text(hjust = 0.5))
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.