I asked a question about the heatmap which was solved here: custom colored heatmap of categorical variables. I defined my scale_fill_manual
for all combinations as suggested in the accepted answer.
Based on this question, I would like to know how to tell ggplot2
to plot a heatmap with all combination of variables and not just the ones that are available in the dataframe (given that they are already in the scale_fill_manual
but are not showing in the final plot).
How can I do this?
The current plotting code:
df <- data.frame(X = LETTERS[1:3],
Likelihood = c("Almost Certain","Likely","Possible"),
Impact = c("Catastrophic", "Major","Moderate"),
stringsAsFactors = FALSE)
df$color <- paste0(df$Likelihood,"-",df$Impact)
ggplot(df, aes(Impact, Likelihood)) + geom_tile(aes(fill = color),colour = "white") + geom_text(aes(label=X)) +
scale_fill_manual(values = c("Almost Certain-Catastrophic" = "red","Likely-Major" = "yellow","Possible-Moderate" = "blue"))
scale_fill_manual contains all combination of Impact, Likelihood
with their respective colors.