0

I have 20 subjects and each subject has 2 durations with different (staggered) start time point and end time point. I would like to make a line chart in R which would look like the lift table in suruvival analysis with staggered entry. To be specific, say the Y-axis is the ID and X-axis is the duration, the plot would be ideally to show the 2 durations stacked for the same ID. Any help would be greatly appreciated.

gagolews
  • 12,836
  • 2
  • 50
  • 75
  • 1
    To "be specific" you could add some data and provide a visual example, like a link to a prototype or other references you know. – Paulo E. Cardoso Apr 22 '14 at 16:01
  • 1
    Here are a few tips on how to make a good reproducible example: http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – Roman Luštrik Apr 22 '14 at 16:25

1 Answers1

0

You can make a blank plot and draw the lines yourself. Here's my attempt at an example based on your description.

R plot

set.seed(500)
df <- data.frame(
    id = 1:20,
    time_start1 = sample(1:25, 20),
    time_end1 = sample(51:75, 20),
    time_start2 = sample(26:50, 20),
    time_end2 = sample(76:100, 20)
)

plot(NULL, NULL, xlim=c(0,100), ylim=c(1,20), 
    xlab="Time", ylab="Identifier")

segments(
    x0=df$time_start1, 
    y0=df$id, 
    x1=df$time_end1, 
    y1=df$id
)
segments(
    x0=df$time_start2, 
    y0=df$id - 0.25, 
    x1=df$time_end2, 
    y1=df$id - 0.25,
    lty=2
)
rsoren
  • 4,036
  • 3
  • 26
  • 37
  • Glad it worked for you. Maybe you could express your gratitude by choosing my answer? Thanks! – rsoren Apr 22 '14 at 21:22
  • Thanks Reed! Yes, I used your approach. By the way, the for loop did not seem necessary for adding the lines. – user3561144 Apr 23 '14 at 20:41
  • Looks like you're new here. To accept an answer, you have to click on the check mark to the left of the text. Here's a link about it: http://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work – rsoren Apr 23 '14 at 21:24