Custom heat map in R

I need to create my own heat map, as shown in the attached figure. It differs from a regular heat map in the sense that I want it to use two color gradients, one for positive values ​​and one for negative values.

enter image description here

As shown in the attached figure, I would like one color to reflect the intensity of values ​​that are positive (or ideally above a certain threshold) and another color to represent the intensity of negative values ​​(alternatively below the threshold).

A small background: I have a binary choice, one option should be preferable for a certain range of data, while the other is preferable to the rest of the data. I want to provide visual help that will show which option / choice is better for different data combinations, but I want the visual help to also provide the β€œgloss” scale that one option has over the other for this instance. Thus, the color will tell you which option to choose, and the color intensity - tell how much better this option compared to the other.

+6
source share
1 answer

here is an example using ggplot2 :

 # sample data df <- data.frame(expand.grid(x = 1:4, y = 1:4), v = runif(16, -10, 10)) # plot ggplot(df, aes(x, y, fill = v, label = sprintf("%.1f", v))) + geom_tile() + geom_text() + scale_fill_gradient2(low = "blue", high = "red") 

enter image description here

+9
source

Source: https://habr.com/ru/post/901677/


All Articles