'Conditional formatting with color coding in R

Hi I am trying to do something similar to Conditional formatting with color as in excel using R. I have a dataset with 0,1,2,3 as their values.

Opp <- c(10968788,11046809,11086342,11097787,11126732,11145638,11163014,11163034,11165910,11167232)
A <- c(1,2,3,2,3,2,2,2,2,2)
B <- c(1,2,3,3,3,2,2,2,2,2)
C <- c(1,2,3,3,3,2,2,2,2,0)
D <- c(2,2,3,3,3,2,3,3,3,3)
E <- c(2,2,3,3,3,3,3,0,3,0)
df <- data.frame(Opp,A,B,C,D,E)

Input enter image description here

Expected Output enter image description here

I tried to get the output using a heatmap but was not successful. Please help

r


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source