Stair step interpolation in R

Steve Simon

2007-11-15

Categories: Blog post Tags: Graphical display R software

I am working on some charts that show discrete (sudden) jumps at specific time points. This requires the use of stair step interpolation

It shows the number of patients at risk during any time point in the study. The number at risk has to be a whole number because it is impossible to have half a patient at risk in a study.

Here’s what it would look like if I just connected the dots.

The programming language R allows you to connect the points either a linear transition (which is what you want for most plots) or using a stair step transition. With a stair step transition

Here’s a simple example. The following R code

plot(0:5,5:0) lines(0:5,5:0,type="s")

will produce this plot.

Notice that when you move from (5,0) to (4,1)

plot(0:5,5:0) lines(0:5,5:0,type="S")

and you get this plot instead.

Now when you move from (5,0) to (4,1)

plot(0:5,5:0) lines(0:5,5:0,type="l")

to get this plot

This plot shows a linear transition between (5,0) and (4,1).