Thank you for looking at my question. I have created a heat map with a color gradient. The color gradient looks good, however, I would prefer that the colors be more defined. The first picture that I have attached here
is what I get when I run my code. The second picture
is what I would like to get. I am not sure how to solve this problem. A small sample of my code is below. To be clear, I would like for my code to return the second picture where the colors distinctly go from green, gold, orange, light red, red, and dark red.
library(RColorBrewer)
library(dplyr)
library(ggplot2)
nRow <- 5
nCol <- 5
m3 <- matrix(c(2,2,3,3,3,1,2,2,3,3,1,1,2,2,3,1,1,2,2,2,1,1,1,1,2), nrow = 5, ncol = 5, byrow = TRUE)
myData <- m3 #matrix(rnorm(nRow * nCol), ncol = nCol)
rownames(myData) <- c("5", "4", "3", "2","1")
colnames(myData) <- c("1", "2", "3", "4","5")
longData <- reshape2::melt(myData)
colnames(longData) <- c("Likelihood", "Consequence", "value")
longData <- mutate(longData, value = Consequence * Likelihood)
cols <-function(n) {
colorRampPalette(rev(c("red4","red2","tomato2","orange","gold1","forestgreen")))(6)
}
display_risk <- mutate(longData, value = Consequence * Likelihood)
ggplot(longData,aes(x = Consequence, y = Likelihood, fill = value)) +
geom_tile() +
scale_fill_gradientn(colours = cols(6)) +
theme(axis.text.y = element_text(angle=90, hjust=1), legend.position = "none") +
scale_x_continuous(name = "Probability", breaks = seq(1,5,1), expand = c(0, 0)) +
scale_y_reverse(name= "Severity", breaks = seq(1,5,1), expand = c(0, 0)) +
geom_hline(yintercept = seq(1.5,5.5)) +
geom_vline(xintercept = seq(1.5,5.5)) +
coord_fixed()
Here are some links to a few answers that I tried with no luck.