1

I am trying to create what is essentially a Gantt chart using ggplot2. I am currently using geom_tile option in ggplot2 to produce something very close to what I need. On the x-axis is month, on the y axis is task, and the color of the blocks is hours of effort for that month.

The issue: The blocks drawn are centered on the month. I need them right justified so that when a month appears, the block sits to the right of the vertical gridline showing that month.

Is there an option like hjust for geom_tile? Here is my code thus far:

myGanttPlot <- ggplot(data=gantt_data, aes(x=workMonth, y=myTasks, fill=Hours, height=0.5)) +
              geom_tile(hjust=1.0) + 
              scale_fill_distiller(palette="RdYlGn") 

I get the error "Unknown parameters: hjust" with this code. Is there a better syntax I should use?

eipi10
  • 91,525
  • 24
  • 209
  • 285
Robert P
  • 13
  • 3
  • 1
    Shifting the value of `workMonth` should take care of this. Does `aes(x=workMonth + 0.5, ...)` do what you need? – eipi10 Apr 14 '16 at 14:55
  • I forgot to mention that workMonth is type POSIXct. But, yes, this appears to work if I add 15 days so that the dates fall in the middle of the month. Good idea--thanks! – Robert P Apr 14 '16 at 15:30

1 Answers1

1

Shifting the value of workMonth by ~15 days should take care of this by centering the tiles between months, rather than on them.

ggplot(data=gantt_data, aes(x=workMonth + 60*60*24*15, y=myTasks, fill=Hours, height=0.5)) +
              geom_tile() + 
              scale_fill_distiller(palette="RdYlGn") 

Without a reproducible example, I can't test the code above, so please let me know if this solves your problem.

eipi10
  • 91,525
  • 24
  • 209
  • 285
  • 1
    Yes, problem solved. I used the functions to add 15 days to my POSIXct time variable to accomplish the above. I used the process outlined here: http://stackoverflow.com/questions/11922181/adding-time-to-posixct-object-in-r – Robert P Apr 14 '16 at 15:37
  • Yes, `POSIXct` dates are in seconds, so you just need to add 60*60*24*15 seconds to add 15 days to your dates. I've updated my answer accordingly. – eipi10 Apr 14 '16 at 15:42