1
votes

I wanted to plot a survival curve using the following data. I called the data file as A.txt and the object 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.

1
No data, so nothing to work with for an example. Look at ?plot and its type="s" as well as at ?stepfun. And do learn to make examples with code so your answers are more helpful.IRTFM
I am so sorry since I am a new user, system didn't allow me to add a figure to clarify what I want to do. Besides, my survival data is consists of two groups that are labelled A and B. In A, 3 subjects died set day 8 and in B, 2 subjects died at day 8 and 2 died in Day 10 post infection. At the end of experiment which Day 15, two subjects are alive in each group. I tried to do a graph for this data. Trying to learn the basic still. Thanks a lot!Lothlorian
Still no data. Use dput() to produce R code that is something you add to the question. (Do read the directions. Don't use comments for what should be edits.)IRTFM
Dear BondedDust, I edited my post and added the data. Hope that help you to solve my problem. Thanks a lot. Sorry for taking your time.Lothlorian
Thank you very much for your help. Now I found it that if I changed the mark.time "mark.time=TRUE" with numeric it labels every time points. Thanks a lot for effort.Lothlorian

1 Answers

1
votes

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. 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. enter image description here