在 ggplot2 中设置 x 轴限制 -> 添加另一条回归线时,x 轴上的数字消失
set x-axis limits in ggplot2 -> when adding another regression line, numbers on x-axis disappear
我想绘制卡普兰迈尔曲线并用威布尔回归线覆盖它。
由于 Weibull 可以做出超过数据生存时间的预测,我想制作 Weibull 回归线 'longer'。我的问题是:当我设置我的 X-asis 时,当 KM 曲线结束时编号结束(见下面的曲线)
这是我的代码:
car2 <- car2[-c(34:39,41,43),] # I only need this variables from the dataset
s1 <- with(car2,Surv(Time_OS_m,Event_OS)) #create survival object
fKM1 <- survfit(s1 ~ Eigenschap,data=car2) #Kaplan meier curve for s1
sWei1 <- survreg(s1 ~ as.factor(Eigenschap),dist='weibull',data=car2) #Weibull regression line
summary(sWei1)
pred.I1 = predict(sWei1, newdata=list(Eigenschap="SA"),type="quantile",p=seq(.01,.99,by=.01))
pred.I2 = predict(sWei1, newdata=list(Eigenschap="I"),type="quantile",p=seq(.01,.99,by=.01))
df1 = data.frame(y=seq(.99,.01,by=-.01), Eigenschap1=pred.I1, Eigenschap2=pred.I2)
df_long1 = gather(df1, key= "Eigenschap", value="Time_OS_m", -y) #Convert to long data format
p = ggsurvplot(fKM1, data = car2, risk.table = TRUE, legend.title="",
legend.labs = c("Infusion", "Screenfailure/\napheresis only"),
title = "Overall Survival (with Weibull distribution)",
pval = TRUE,
pval.coord = c(0, 0.03),
pval.size = 3.5,
xlim = c(0,70)) #here i set the X axis limits
p$plot = p$plot + geom_line(data=df_long1, aes(x=Time_OS_m, y=y, group=Eigenschap))
p
上面的代码给出了这个情节:
谁能帮我把 x 轴一直编号到最后,我这里做错了什么?
这可以通过参数 break.x.by
来实现。
使用 survminer::ggsurvplot
中的第一个示例试试这个:
library(survey)
library(survminer)
fit <- survfit(Surv(time, status) ~ sex, data = lung)
# Basic survival curves
ggsurvplot(fit, data = lung, xlim = c(0, 1500))
ggsurvplot(fit, data = lung, xlim = c(0, 1500), break.x.by = 250)
我想绘制卡普兰迈尔曲线并用威布尔回归线覆盖它。 由于 Weibull 可以做出超过数据生存时间的预测,我想制作 Weibull 回归线 'longer'。我的问题是:当我设置我的 X-asis 时,当 KM 曲线结束时编号结束(见下面的曲线)
这是我的代码:
car2 <- car2[-c(34:39,41,43),] # I only need this variables from the dataset
s1 <- with(car2,Surv(Time_OS_m,Event_OS)) #create survival object
fKM1 <- survfit(s1 ~ Eigenschap,data=car2) #Kaplan meier curve for s1
sWei1 <- survreg(s1 ~ as.factor(Eigenschap),dist='weibull',data=car2) #Weibull regression line
summary(sWei1)
pred.I1 = predict(sWei1, newdata=list(Eigenschap="SA"),type="quantile",p=seq(.01,.99,by=.01))
pred.I2 = predict(sWei1, newdata=list(Eigenschap="I"),type="quantile",p=seq(.01,.99,by=.01))
df1 = data.frame(y=seq(.99,.01,by=-.01), Eigenschap1=pred.I1, Eigenschap2=pred.I2)
df_long1 = gather(df1, key= "Eigenschap", value="Time_OS_m", -y) #Convert to long data format
p = ggsurvplot(fKM1, data = car2, risk.table = TRUE, legend.title="",
legend.labs = c("Infusion", "Screenfailure/\napheresis only"),
title = "Overall Survival (with Weibull distribution)",
pval = TRUE,
pval.coord = c(0, 0.03),
pval.size = 3.5,
xlim = c(0,70)) #here i set the X axis limits
p$plot = p$plot + geom_line(data=df_long1, aes(x=Time_OS_m, y=y, group=Eigenschap))
p
上面的代码给出了这个情节:
谁能帮我把 x 轴一直编号到最后,我这里做错了什么?
这可以通过参数 break.x.by
来实现。
使用 survminer::ggsurvplot
中的第一个示例试试这个:
library(survey)
library(survminer)
fit <- survfit(Surv(time, status) ~ sex, data = lung)
# Basic survival curves
ggsurvplot(fit, data = lung, xlim = c(0, 1500))
ggsurvplot(fit, data = lung, xlim = c(0, 1500), break.x.by = 250)