0

I have the following DF that has hypothetical data on sales of various items in supermarkets across different towns.

Town <- c("Town A","Town B", "Town C")
Vegetables <- c(20, 30, 40)
Fruits <- c(40, 20,30)
Toiletries <- c(30, 20,40)

Given that the real data frame will have 50 as the highest value, I'd like to color code the cells in the data frame with different colors. e.g 10="red", 20="green", 30="blue", 40="yellow" and 50="purple".

The data frame aims to have a similar look as a correlation matrix (see picture) but with the above custom colours. enter image description here

The table will be rendered in a shiny dashboard.

Please point me to a way how to achieve this.

Ameya
  • 504
  • 3
  • 12
andy
  • 1,947
  • 5
  • 27
  • 46
  • You can do it [with the `gt` package](https://gt.rstudio.com/reference/data_color.html), [with the `DT` package](https://stackoverflow.com/a/31325653/903061), and probably several others. Those were just the first hits when I searched for "r table color cells". – Gregor Thomas Oct 25 '22 at 19:02
  • Can you give an example of where you are and what steps you need help with? Do you already know how you're plotting this (ggplot2?) and just need help setting up the binning of the colors? Do you need help plotting the whole thing? – divibisan Oct 25 '22 at 19:31

0 Answers0