title: in R, plot sucessive/sequence events
body: <p>EDITED: following the recommendation </p>
  
  <p>I am trying to create a simple plot of the frequency of consecutive events based on this post: <a href="https://stackoverflow.com/questions/11476090/ggplot-sequence-patterns">ggplot sequence patterns</a></p>
  
  <p>I would like to pile up the same plot but for others subjects ( different sequences)
  Subjects <code>"aa", "bb", "cc"</code></p>
  
  <p>The example dataset is as follow:</p>
  
  <pre><code>subject &lt;- c("aa","aa","aa","aa","aa","aa","aa", "bb","bb","bb","bb","bb","bb","bb","cc","cc","cc","cc","cc","cc","cc")
  event &lt;- c("P","C","D","C","P","E","D","C","P","E","D","P","C","E","P","E","D","P","C","x","x")
  freq &lt;- c(3,2,1,4,2,1,0,3,4,1,3,3,1,2,1,3,2,1,4,0,0))
  
  dfx &lt;- data.frame(subject, event, freq)
  </code></pre>
  
  <p>The result I get is:
  <img src="https://i.stack.imgur.com/yynKE.png" alt="my result, bad"></p>
  
  <p>Using this code, based on the original post:</p>
  
  <pre><code>library(ggplot2)
  
  dfx$type &lt;- factor(dfx$type)
  dfx$ymin &lt;- c(0,1,2)
  dfx$ymax &lt;- c(1,2,3)
  dfx$xmax &lt;- cumsum(dfx$count)
  dfx$xmin &lt;- c(0, head(dfx$xmax, n=-1))
  
  plot_x &lt;- ggplot(dfx, 
              aes(xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,fill=type))   +geom_rect(colour="grey40", size=0.5)
  
  png("plot_x.png", height=200, width=800)
  print(plot_x)
  dev.off()
  </code></pre>
  
  <p>I have created this image with what I would like to plot. ( it is handmade in excel). In this case, we have 3 subjects, 4 events (C,P, D,E)+1 dummy event(X), necessary to create the data frame. As you can see, the total number of events is not necessary equal on each subject.
  <img src="https://i.stack.imgur.com/8x4kI.png" alt="expected"></p>