Survminer
产生不错的情节,但有没有办法进一步改变常规的结果ggplot
-命令?
我尝试做的是使 y 轴从原点开始,如上所述here https://stackoverflow.com/questions/13701347/force-the-origin-to-start-at-0-in-ggplot2-r。
对于常规 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’添加另一个比例,这将取代现有的比例。”
和一个额外的错误
“错误:提供给连续刻度的离散值”
有办法解决这个问题吗?
解决您的问题的一个可能的解决方案是修改ggsurvplot
and ggrisktable
插入expand=c(0,0)
在适当的地方。
在这link https://pastebin.com/rNwRHBzE你可以找到我的建议。
点击“下载”并保存文件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)
Here is the plot:
希望它可以帮助你。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)