-3

I have a bunch of data with a YYYY-MM-DD date attached to it, and I'm having trouble getting a single bar for each year. In other words, all data from 2014 showing up under a bar for 2014.

The dates were converted to the YYYY-MM-DD format using

df1$Close.Date <- as.Date(df1$Close.Date, "%m/%d/%Y")

Here's my histogram formula that doesn't group correctly

ggplot(df1, aes(Close.Date, fill=Stage)) + geom_bar()

I've tried messing around with breaks and binwidth with no success

Mako212
  • 6,787
  • 1
  • 18
  • 37
  • 2
    In the `aes`, where is the `y` variable? – akrun Aug 05 '15 at 20:25
  • 1
    Besides what @akrun mentioned, you may want to `aggregate` your data by year, otherwise you can get multiple values per year, but we can't be sure since we don't know what your data looks like. – Bernardo Aug 05 '15 at 20:29
  • @Bernardo Thanks! Sometimes the solution is so simple you kick yourself. I added this line `df1$yr <- strftime(df1$Close.Date, "%Y")` and then replaced Close.Date with yr in the ggplot line. – Mako212 Aug 05 '15 at 23:52

1 Answers1

0

I fixed it by: adding this line df1$yr <- strftime(df1$Close.Date, "%Y") and then replacing Close.Date with yr in the ggplot line.

Mako212
  • 6,787
  • 1
  • 18
  • 37