Assuming I have a data frame as such:
Date <- seq(as.Date("1990-03-01"), by = 'quarters', length.out=100)
Date<- as.yearqtr(Date, format="%Y-%m-%d")
A <- runif(100, 500, 2000)
B <- runif(100, 200, 1000)
C <- runif(100, 1000, 5000)
df <- data.frame(Date, A, B, C)
I would like to create a heatmap using ggplot2 but apply a different conditional discrete colour scale to each variable A and B based on the percentile of each of its value. i.e. For values below the 25th percentile > red, for values between 25th to 50th percentile > orange, for values between 50th to 75th percentile > yellow, for values between 75th to 100th percentile > green.
I could create a heatmap on ggplot geom_tiles by using the melt function and making x=Date and y=variable, with fill=value. However, they will take the value of all the variables as one vector and give the 25th percentile based on all the combined values. Is there a way to separately condition the scale_fill_manual based on the percentiles of individual variables A, B, C. In that case I would probably need to apply multiple scale_fill_manual functions.
Alternatively is there any way which I can stack the ggplot on top of each other since I have been able to create individual heatmaps for each variable. I have been struggling with this for a while and any help is appreciated, thank you very much.