简体   繁体   English

具有survfit的R中的生存曲线

[英]Survival Curve in R with survfit

I wanted to plot a survival curve using the following data. 我想使用以下数据绘制生存曲线。 I called the data file as A.txt and the object A 我将数据文件称为A.txt ,将对象称为A

A <- read.table(text = "
Time Status Group
8 1 A
8 1 A
8 1 A
9 1 A
9 1 A
9 1 A
15 0 A
15 0 A
7 1 B
7 1 B
8 1 B
9 1 B
10 1 B
10 1 B
15 0 B
15 0 B", header = TRUE)

I tried to plot a survival curve using this code: 我尝试使用以下代码绘制生存曲线:

title(main="Trial for Survival Curve")
fit <- survfit(Surv(Time, Status) ~ Group, data = A)
par(col.lab="red")
legend(10, .9, c("A", "B"), pch=c(2,3),col=2:3)
plot(fit, lty=2:3, col=2:3,lwd=5:5, xlab='Time(Days)',
  ylab='% Survival',mark.time=TRUE,mark=2:3)

I would like to put marks (triangle for A and "+" for B ) every time when survival % decreases for instance at Day 7 and Day 8. I want this labeling throughout the graph, but it adds the labels only at the end of the experiment. 我想放标记(三角形为A"+"B )每当存活%在7天和第8天我想整个图表这个标记例如减小,但它仅在末端添加标签本实验。

First, I'd recommend rearranging the plotting calls: 首先,我建议重新安排绘图调用:

par(col.lab="red")
plot(fit, lty=2:3, col=2:3,lwd=5:5, xlab='Time(Days)',
  ylab='% Survival',mark.time=TRUE,mark=2:3)
title(main="Trial for Survival Curve")
legend(10, .9, c("A", "B"), pch=c(2,3),col=2:3)

You can add points to the survival plot with the points function. 您可以使用points函数将点添加到生存图。 However, it looks like there's a small bug, which you can get around fairly easily: 但是,似乎有一个小错误,您可以轻松解决它:

firsty <- 1 ## Gets around bug
points(fit[1], col = 2, pch = 2) # Plots first group in fit
points(fit[2], col = 3, pch = 3) # Plots second group in fit

The points are plotted at the bottom of the "cliff" in the survival plot. 这些点绘制在生存图中“悬崖”的底部。 在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM