Grid: different background color (of row) based on values

Here is a solution with Item[...] :

itemRules = 
  With[{color = RandomColor[]},
    (x : {___, #}) :>  (Item[#,Background -> color] & /@ x)] & /@ Union[list[[All, 4]]];

Grid[list /. itemRules, Dividers -> All] 

enter image description here


sets = GatherBy[Transpose[{Range[Length[list]], list[[All, 4]]}], #[[2]] &];
colors = {LightYellow, LightOrange, LightBlue};
colorrules = 
 Flatten@Table[
   Thread[sets[[n, All, 1]] -> colors[[n]]], {n, Length[sets]}];

Grid[list, Frame -> All, Background -> {None, colorrules}]

enter image description here


Using Association and Lookup to specify row backgrounds:

keys = Union @ list[[All, -1]];
colors = Lighter @* Lighter @* ColorData["Rainbow"] /@ Rescale[keys];
backgroundColors = AssociationThread[keys, colors];

Legended[Grid[list,  Frame -> All, 
  Background -> {None, Lookup[list[[All, -1]]] @ backgroundColors}],
 SwatchLegend[colors, keys]]

enter image description here

Tags:

Grid Layouts