【问题标题】:ggsurvplot - axes crossing at 0,0ggsurvplot - 轴在 0,0 处交叉
【发布时间】:2017-10-16 22:03:54
【问题描述】:

Survminer 产生了不错的情节,但是有没有办法通过常规的ggplot-commands 进一步改变结果?

我尝试做的是使 y 轴从原点开始,如 here 所述。 对于常规的 ggplot,这可以完美运行,但我无法使其与 survminer 一起使用:

library(survival)
library(survminer)

df<-genfan
df$treat<-sample(c(0,1),nrow(df),replace=TRUE)


fit <- survfit(Surv(hours, status) ~ treat,
               data = df)

p<-ggsurvplot(fit, data = df, risk.table = TRUE,,ncensor.plot=FALSE,tables.theme = theme_cleantable(),
              ggtheme = theme_survminer(font.legend=c(12,"bold","black") ))


p%+%scale_x_continuous(expand=c(0,0))%+%scale_y_continuous(expand=c(0,0))

这会产生错误

“'y' 的比例已经存在。为 'y' 添加另一个比例,它将替换现有比例。”

还有一个额外的错误

“错误:提供给连续刻度的离散值”

有没有办法解决这个问题?

【问题讨论】:

  • 我们如何获得genfan?第一条消息是警告,而不是错误。第二条消息与risk table = TRUE 有关,这似乎使第二个图具有离散的 y 轴而不是连续的 y 轴,这会导致错误。
  • @aosmith genfansurvival 包中的一个数据集。

标签: r ggplot2 survival-analysis


【解决方案1】:

解决您的问题的一个可能方法是修改ggsurvplotggrisktable,在适当的位置插入expand=c(0,0)
在这个link 你可以找到我的建议。
点击“下载”并将文件a_modified_ggsurvplot.txt保存在您的工作目录中。
然后运行以下代码:

library(survival)
library(survminer)

df <- genfan
df$treat <- sample(c(0,1),nrow(df),replace=TRUE)
fit <- survfit(Surv(hours, status) ~ treat, data = df)

source("a_modified_ggsurvplot.txt")
p <- myggsurvplot(fit, data = df, risk.table = TRUE,
     ncensor.plot=FALSE,tables.theme = theme_cleantable(),
     ggtheme = theme_survminer(font.legend=c(12,"bold","black")))
print(p)

剧情如下:

希望对你有帮助。

【讨论】:

    猜你喜欢
    • 2021-04-08
    • 1970-01-01
    • 1970-01-01
    • 2019-07-19
    • 2023-03-09
    • 1970-01-01
    • 1970-01-01
    • 2019-07-27
    • 2010-11-30
    相关资源
    最近更新 更多