0

I have constructed this plot in ggplot2:

Using this code:

   m_date = c( rep("2015-09-13", 3),  rep("2015-09-14", 3), rep("2015-09-15", 3))
   M_date = as.Date(m_date)
   M_hour = c(11, 12, 13, 11, 12, 13, 11, 12, 13)
   M_Count = c(1, 2, 3, 4, 5, 6, 7, 8, 9)
   M_WE = c(1, 1, 1, 0, 0, 0, 0, 0, 0)
   Mock = data.frame(M_date, M_hour, M_Count, M_WE)
   p1 = qplot(M_date, M_hour, fill=M_Count, data=Mock, geom="tile")
   p1 = p1 + scale_x_date() + scale_y_reverse() + scale_fill_gradient(low = "white", high = "green2")
   print(p1)

I want to try to vary the color of the gradient by the variable by the variable M_WE (I want the weekends to be blue, and the weekdays to be green.) Is it is possible? I was able to create new columns for weekend and weekday counts, and two separate graphs but then was not able to combine them.

Many Thanks! Dustin

aosmith
  • 34,856
  • 9
  • 84
  • 118
Dustin T.
  • 11
  • 3
  • 1
    Take a look at [this question/answer](http://stackoverflow.com/questions/24822621/multiple-legends-in-a-plot-with-geom-tile) and see if it is similar to what you are trying to do. – aosmith Oct 20 '15 at 14:03
  • A O Smith, awesome! That is exactly what I was looking for. – Dustin T. Oct 20 '15 at 16:38

0 Answers0