title: Trouble with placing and formatting dates in ggplot2 graph using chron
body: <p>I've been trying to add appropriate dates on the x-axis of my graph, but can't figure out how to do it in a sane way. What I want is pretty simple: a date at every January 1st in between the minimum and maximum of my data set.</p>
  
  <p>I don't want to include the month - just '2008' or '2009' or whatever is fine. A great example would be this graph:</p>
  
  <p><a href="http://blog.stephenwolfram.com/data/uploads/2012/03/outgoing-mail-diurnal-image.png" rel="nofollow">example graph</a></p>
  
  <p>Except I want the date on every year, rather than every other year.</p>
  
  <p>I can't seem to figure this out. My dates are defined as days since 1/1/1970, and I've included a method <code>dateEPOCH_formatter</code> which converts the epoch format to a format using the chron package. I've figured out how to make a tick mark and date at the origin of the graph and every 365 days thereafter, but that's not quite the same thing.</p>
  
  <p>Another minor problem is that, mysteriously, the line <code>chron(floor(y), out.format="mon year",origin.=epoch)</code> outputs a graph with axis markers like 'Mar 2008', but changing the line to <code>chron(floor(y), out.format="year",origin.=epoch)</code> doesn't give me a result like '2008' - it just results in the error:</p>
  
  <pre><code>Error in parse.format(format[1]) : unrecognized format year
  Calls: print ... as.character.times -&gt; format -&gt; format.dates -&gt; parse.format
  Execution halted
  </code></pre>
  
  <p>Here's my code - thanks for the help.</p>
  
  <pre><code>library(ggplot2)
  library(chron)
  argv &lt;- commandArgs(trailingOnly = TRUE)
  mydata = read.csv(argv[1])
  png(argv[2], height=300, width=470)
  
  
  timeHMS_formatter &lt;- function(x) {                  # Takes time in seconds from midnight, converts to HH:MM:SS
  h &lt;- floor(x/3600)
  m &lt;- floor(x %% 60)
  s &lt;- round(60*(x %% 1))                         # Round to nearest second
  lab &lt;- sprintf('%02d:%02d', h, m, s)        # Format the strings as HH:MM:SS
  lab &lt;- gsub('^00:', '', lab)                    # Remove leading 00: if present
  lab &lt;- gsub('^0', '', lab)                      # Remove leading 0 if present
  }
  
  dateEPOCH_formatter &lt;- function (y){
  epoch &lt;- c(month=1,day=1,year=1970)
      chron(floor(y), out.format="mon year",origin.=epoch)
  }
  
  p=  ggplot() + 
  coord_cartesian(xlim=c(min(mydata$day),max(mydata$day)), ylim=c(0,86400)) +         # displays data from first email through present
  scale_color_hue() +
  xlab("Date") +
  ylab("Time of Day") +
  scale_y_continuous(label=timeHMS_formatter, breaks=seq(0, 86400, 14400)) +              # adds tick marks every 4 hours
  scale_x_continuous(label=dateEPOCH_formatter, breaks=seq(min(mydata$day), max(mydata$day), 365) ) +
  ggtitle("Email Sending Times") +                                                        # adds graph title
  theme( legend.position = "none", axis.title.x = element_text(vjust=-0.3)) +
  theme_bw() +
  layer(
      data=mydata, 
      mapping=aes(x=mydata$day, y=mydata$seconds), 
      stat="identity", 
      stat_params=list(), 
      geom="point", 
      geom_params=list(alpha=5/8, size=2, color="#A9203E"),
      position=position_identity(),
  )   
  
  print(p)
  dev.off()
  </code></pre>