title: Cumulative Frequency Tables and Chart Output
body: <p>I'm working with some rather large time-series data sets related to futures prices and am in the process of converting some calculations which I previously did in Excel to R. This conversion has been relatively straightforward thus far but I m having a bit of trouble replicating my histograms with their cumulative frequency distributions in R as I had them in Excel. If you're familiar with Excel, the Histogram function in the Data Analysis Toolpack automatically creates a Cumulative Frequency Distribution table with the cumulative percentages of each, in this case, Price Level, next to the histogram.</p>
  
  <p>I've had some success creating some basic histograms using ggplot, here is a snippet of that code:</p>
  
  <pre><code>ggplot(data=CrudeRaw, aes(x=CrudeRaw$X7_1_F))+
   geom_histogram(breaks=seq(X7_F_M_L, X7_F_M_H, by=0.01),
                   col="blue",
                   fill="white",
                   alpha= 0.2)+
    labs(title="X7 1 Month Price Distribution", x="Price Levels", 
    y="Frequency") +
    xlim(c(X7_F_M_L, X7_F_M_H)) +
    ylim(c(0,100))
  </code></pre>
  
  <p>Several questions regarding formatting and usage.</p>
  
  <p>a) CrudeRaw is a dataframe which contains roughly 276 rows, and no less then 50 columns. For the purposes of this project I've chopped the data into 20 period, 60 period, 120 period, 180 period, and 240 period subsets. The data is in chronological order by date.</p>
  
  <p>Question(s): ggplot cannot take numeric data types, only data frames, so I can only feed it the entire df even though I am interested in creating distributions for the aforementioned subsets. Is there a way that I can still do this?</p>
  
  <p>b) How do I get every bin (price) to show up on the x-axis rather than a number marking every 5 bins (-15, -10, -5, 0, 5 ..., 15)?</p>
  
  <p>c) I've successfully created a cumulative frequency table using the follow code,</p>
  
  <pre><code>round(cbind(cumsum(table(X7_F)))/NROW(X7_F),2)
  </code></pre>
  
  <p>But I'd like a way to a) output each of these tables (of which there are many) to a CSV file OR, ideally create a "report" of sorts with R which can be saved to a pdf, or perhaps even within the histogram which the table/data is associated with.</p>
  
  <p>d) I've done some searching on how to output data to a CSV file, but it wasnt clear from the examples I went over how I could output multiple arrays to the same sheet or workbook, en masse. That is, I would like to output my 20, 60, 120, 180, and 240 period arrays of prices to the same workbook. I'm thinking that by creating another dataframe that I could then pass these subsets of the data to the ggplot function like I mentioned I was having trouble doing in part a)</p>
  
  <p>e)  Lastly (for now) how do I overlay the CFD onto my histograms?</p>
  
  <p>Please advise if you require any additional information or colour in order to help me and many thanks in advance for your responses!</p>