Tell me more ×
Cross Validated is a question and answer site for statisticians, data analysts, data miners and data visualization experts. It's 100% free, no registration required.

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)
library(ggplot2)
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?
share|improve this question
2  
Did you look at the on-line help, had.co.nz/ggplot2/geom_step.html? – chl Aug 22 '11 at 10:25
Yes, this is it. Missed this in documentation. – Yuriy Petrovskiy Aug 22 '11 at 10:38
1  
@Yuriy, please answer your question. It would help future users with similar problems. – mpiktas Aug 22 '11 at 10:42
@mpiktas, added an answer for the main question. Any opinions on other questions? – Yuriy Petrovskiy Aug 22 '11 at 12:16

1 Answer

up vote 3 down vote accepted

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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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