Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
490 views
in Technique[技术] by (71.8m points)

graphics - Custom Heat Map in R

I need to create custom heat map as illustrated in the attached figure. It is different from a conventional 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 depict the intensity of the values that are positive (or ideally above a certain threshold) and another color to depict the intensity of the values that are negative (alternatively, below the threshold).

A little background: I have a binary choice set, one option is to be preferred for a certain range of data while the other is preferred for the remaining data. I want to provide a visual aid that will depict which option/choice is better for the different combinations of data but I want the visual aid to also provide the scale of "betterness" that one option has over the other for that instance. So the color would tell which option to pick while the intensity of the color with tell how much better is that option compared to the other.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...