r - Using Multiple scale_fill_manual in ggplot2 -


assuming have data frame such:

date <- seq(as.date("1990-03-01"), = 'quarters', length.out=100) date<- as.yearqtr(date, format="%y-%m-%d") <- runif(100, 500, 2000) b <- runif(100, 200, 1000) c <- runif(100, 1000, 5000) df <- data.frame(date, a, b, c) 

i create heatmap using ggplot2 apply different conditional discrete colour scale each variable , b based on percentile of each of value. i.e. values below 25th percentile > red, values between 25th 50th percentile > orange, values between 50th 75th percentile > yellow, values between 75th 100th percentile > green.

i create heatmap on ggplot geom_tiles using melt function , making x=date , y=variable, fill=value. however, take value of variables 1 vector , give 25th percentile based on combined values. there way separately condition scale_fill_manual based on percentiles of individual variables a, b, c. in case need apply multiple scale_fill_manual functions.

alternatively there way can stack ggplot on top of each other since have been able create individual heatmaps each variable. have been struggling while , appreciated, thank much.

this should color coding:

date <- seq(as.date("1990-03-01"), = 'quarters', length.out=100) date<- as.yearqtr(date, format="%y-%m-%d") <- runif(100, 500, 2000) b <- runif(100, 200, 1000) c <- runif(100, 1000, 5000) df <- data.frame(date, a, b, c)  df  quanta <- quantile(df$a, c(0.25, 0.75)) quantb <- quantile(df$b, c(0.25, 0.75)) quantc <- quantile(df$c, c(0.25, 0.75))  df$quanta  <- with(df, factor(ifelse(a < quanta[1], 0,                                        ifelse(a < quanta[2], 1, 2)))) df$quantb  <- with(df, factor(ifelse(b < quantb[1], 0,                                       ifelse(b < quantb[2], 1, 2)))) df$quantc  <- with(df, factor(ifelse(c < quantc[1], 0,                                       ifelse(c < quantc[2], 1, 2)))) 

please see post more details on color coding based on percentiles:

color code points based on percentile in ggplot

and 1 color coding based on multiple variables:

r ggplot barplot; fill based on 2 separate variables


Comments

Popular posts from this blog

sequelize.js - Sequelize group by with association includes id -

android - Robolectric "INTERNET permission is required" -

java - Android raising EPERM (Operation not permitted) when attempting to send UDP packet after network connection -