2

My df:

prod
# A tibble: 695 × 3
   REPORT_DATE  UNIT   PROD
        <date> <chr>    <dbl>
1   2015-03-28 DEP11 2.043962
2   2015-03-29 DEP11 2.788490
3   2015-03-30 DEP11 2.795274
4   2015-03-31 DEP11 3.100589
5   2015-04-01 DEP11 2.882843
6   2015-04-02 DEP11 2.987861
7   2015-04-03 DEP11 3.123047
8   2015-04-04 DEP11 3.264180
9   2015-04-05 DEP11 2.987729
10  2015-04-06 DEP11 3.222573
# ... with 685 more rows

I created a ggTimeSeries plot as below: enter image description here

I want to change the colour scheme...and want to divide the colour into 3 categories:

  1. below 3.0 = red
  2. 3.0 - 3.2 = amber
  3. greater than 3.2 = green

I have tried the following:

ggplot_calendar_heatmap(
   prod,
   'REPORT_DATE',
   'PROD'
) +
   xlab('') + 
   ylab('') + 
   scale_fill_continuous(low = 'red', high = 'green') + 
   facet_wrap(~Year, ncol = 1)

also tried to use scale_colour_gradientn and scale_colour_manuel but no luck... any ideas?

Steffen Moritz
  • 7,277
  • 11
  • 36
  • 55
Shery
  • 1,808
  • 5
  • 27
  • 51

1 Answers1

2

Something like this should work:

set.seed(1)
# generate some random data
prod <- data.frame(REPORT_DATE=seq.Date(as.Date('2015/01/03'), as.Date('2017/02/28'), by='day')) 
prod$PROD <- runif(nrow(prod), 0, 5)
prod <- transform(prod, PROD.cut=cut(PROD, breaks=c(-Inf,3, 3.2,Inf)))           # bin data
library(ggTimeSeries)
ggplot_calendar_heatmap(
  prod,
  'REPORT_DATE',
  'PROD.cut'
) +
  xlab('') + 
  ylab('') + 
  scale_fill_manual(values = c("red", "orange", "green")) +
  #scale_fill_continuous(low = 'red', high = 'green') + 
  facet_wrap(~Year, ncol = 1)

enter image description here

Sandipan Dey
  • 21,482
  • 2
  • 51
  • 63