I have the graph like this: enter image description here

R code for generating it is:

DF <- data.frame(date = as.Date(runif(100, 0, 800),origin="2005-01-01"), 
                 outcome = rbinom(100, 1, 0.1))
DF <- DF[order(DF$DateVariable),] #Sort by date
DF$x <- seq(length=nrow(DF)) #Add case numbers (in order, since sorted)
DF$y <- cumsum(DF$outcome)
ggplot(DF, aes(x,y)) + geom_path() + #Ploting
scale_y_continuous(name= "Number of failures") +
scale_x_continuous(name= "Operations performed")

I want something like this: enter image description here

The difference is in the form of steps in case of failure (I need rectangular).

My questions are:

  • How to achieve this with ggplot2?
  • Is there any better option for visualizing failure rate over time/iterations performed?
  • What variant is easier to understand: this or that or, maybe something different?
  • 2
    $\begingroup$ Did you look at the on-line help, had.co.nz/ggplot2/geom_step.html? $\endgroup$
    – chl
    Aug 22, 2011 at 10:25
  • $\begingroup$ Yes, this is it. Missed this in documentation. $\endgroup$ Aug 22, 2011 at 10:38
  • 2
    $\begingroup$ @Yuriy, please answer your question. It would help future users with similar problems. $\endgroup$
    – mpiktas
    Aug 22, 2011 at 10:42
  • $\begingroup$ @mpiktas, added an answer for the main question. Any opinions on other questions? $\endgroup$ Aug 22, 2011 at 12:16

1 Answer 1


As noted by @chl the answer is simply using geom_step() instead of geom_path() in the example above.

Result (the plot has different data):

enter image description here


Not the answer you're looking for? Browse other questions tagged or ask your own question.