ggsurvplot - 轴在 0,0 处交叉
ggsurvplot - axes crossing at 0,0
Survminer
生成了漂亮的图,但是有没有办法通过常规 ggplot
-命令进一步改变结果?
我尝试做的是使 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))
这会产生错误
"Scale for 'y' is already present. Adding another scale for 'y', which will replace the existing scale."
还有一个错误
"Error: Discrete value supplied to continuous scale"
有什么办法解决这个问题吗?
您的问题的可能解决方案是修改 ggsurvplot
和 ggrisktable
,在适当的位置插入 expand=c(0,0)
。
在这个 link 你可以找到我的建议。
单击 "download" 并将文件 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)
剧情如下:
希望对您有所帮助。
Survminer
生成了漂亮的图,但是有没有办法通过常规 ggplot
-命令进一步改变结果?
我尝试做的是使 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))
这会产生错误
"Scale for 'y' is already present. Adding another scale for 'y', which will replace the existing scale."
还有一个错误
"Error: Discrete value supplied to continuous scale"
有什么办法解决这个问题吗?
您的问题的可能解决方案是修改 ggsurvplot
和 ggrisktable
,在适当的位置插入 expand=c(0,0)
。
在这个 link 你可以找到我的建议。
单击 "download" 并将文件 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)
剧情如下:
希望对您有所帮助。