0

I am doing a survival analysis and have produced the survival graph using

  1. plot function to plot the Kaplan-Meier(KA variable) estimate as y value against time.

  2. lines function to plot the step lines between estimate i and i+1, for each i=1,2,....

The code is as follows:

plot(KA)

for( i in 1:(length(KA)-1)){

lines(c(i,i+1),c(KA[i],KA[i]))       # The horizontal step lines

lines(c(i+1,i+1),c(KA[i],KA[i+1]))   # The vertical step lines

}

Now I want to make a more beautiful survival graph using ggplot2 package.

The question is: how to add the step lines into the graph?

I'm sorry, I can not put graphs as my reputation is less than 10.

yi.tang.uni
  • 103
  • 1
  • 6
  • Following the suggestions here will yield better answers for you and the community: http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – Chase Apr 06 '12 at 21:09
  • Here is some example Code: http://www.ceb-institute.org/bbs/wp-content/uploads/2011/09/ggplot2-tutorial-code.txt – EDi Apr 06 '12 at 21:15

1 Answers1

1

Have a look at either geom_step, geom_path or geom_segment.
They might be helpful in what you are trying to achieve.

http://had.co.nz/ggplot2/geom_step.html
http://had.co.nz/ggplot2/geom_path.html
http://had.co.nz/ggplot2/geom_segment.html

wligtenberg
  • 7,695
  • 3
  • 22
  • 28