5

Like the histogram shown below:

plot
(source: cern.ch)

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
xiaoxiao87
  • 783
  • 1
  • 8
  • 20

2 Answers2

8

Maybe with geom_step

library('ggplot2')

set.seed(1)
x <- unlist(Map(rpois, 20, 4:1 * 5))
qplot(seq_along(x), x, geom = 'step')

enter image description here

rawr
  • 20,481
  • 4
  • 44
  • 78
  • Hi, thank you for your answer! Though for this particular problem I would like to see a more generic solution (i.e. using the histogram option). The reason is this solution requires getting the bin content for each bin which may not be straightforward. – xiaoxiao87 Apr 29 '15 at 21:50
  • 3
    @xiaoxiao87 `x <- hist(data)$counts` if you gave some example data, I could attempt a better answer – rawr Apr 29 '15 at 21:55
  • Got it. Thanks! This almost solved the problem except the left/right side of the steps is empty. – xiaoxiao87 Apr 29 '15 at 22:03
  • 1
    I'm not sure what you mean – rawr Apr 29 '15 at 22:14
7

A less satisfying way, using layering of a black color hitsogram under one with no color with white fill.

set.seed(12)
x <- rpois(1000, 30)

bw <- 2
col <- 'black'
ggplot(data.frame(x), aes(x=x)) + 
    geom_histogram(binwidth=bw, color = col, fill=col, size=2) +
    geom_histogram(binwidth=bw, fill='white') +
    theme_bw()

enter image description here

Tyler Rinker
  • 108,132
  • 65
  • 322
  • 519