简体   繁体   English

R生存曲线阶梯图格式?

[英]R Survival Curve staircase plot format?

I'm currently trying to make a survival curve using R. However, the survfit() and Surv() functions enter data in a different format that I have. 我目前正在尝试使用R绘制生存曲线。但是,survfit()和Surv()函数以与我不同的格式输入数据。 The data in this example gives a bunch of organisms and the amount of time until they die, and the Surv function basically calculates the proportion of individuals alive at any given time. 示例中的数据提供了一堆生物体以及直至它们死亡的时间,Surv函数基本上计算了在任何给定时间活着的个体的比例。

However, the data that I have is in a different format. 但是,我拥有的数据格式不同。 I have the columns represent the day number, the rows represent each trial, and the values represent the percent that survive at any given time. 我的列代表天数,行代表每个试验,值代表在任何给定时间存活的百分比。 Currently, I could just theoretically do a regular plot of these, but I want to make a staircase-like plot, similar to what I would get in the survfit() function. 目前,从理论上讲,我可以对这些图进行常规绘制,但是我想制作一个类似于楼梯的图,类似于在survfit()函数中得到的图。 How would I do this? 我该怎么做?

Here's some sample data in the format I'm using. 这是一些我使用的格式的示例数据。

            1   2   3   4   5   6   7   8   9   10
Treatment 1 100 95  90  86  82  78  74  70  67  64
Treatment 2 100 90  81  73  66  59  53  48  43  39
Treatment 3 100 85  72  61  52  44  37  31  26  22

dd <- structure(list(trial = structure(1:3, .Label = c("Treatment 1", 
"Treatment 2", "Treatment 3"), class = "factor"), X1 = c(100L, 
100L, 100L), X2 = c(95L, 90L, 85L), X3 = c(90L, 81L, 72L), X4 = c(86L, 
73L, 61L), X5 = c(82L, 66L, 52L), X6 = c(78L, 59L, 44L), X7 = c(74L, 
53L, 37L), X8 = c(70L, 48L, 31L), X9 = c(67L, 43L, 26L), X10 = c(64L, 
39L, 22L)), .Names = c("trial", "X1", "X2", "X3", "X4", "X5", 
"X6", "X7", "X8", "X9", "X10"), class = "data.frame", row.names = c(NA, 
-3L))

这是另一种方法,而不必使用@rawr在注释中建议的for循环:

matplot(t(dd[,-1]),type = "s")

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

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