Skip to content

Assigning colors to cells

2 messages · Sumukh Sathnur, Dennis Murphy

#
Hi everyone,

I was wondering if there was a simple way to assign a color to a cell 
based on value in a data frame and return the cell as an image? For 
example, if the value is >1, then blue, if between 1 and 2, green, if 
between 2 and 3, yellow, etc.

I tried using a heatmap function but I was hoping there was an easier 
way to do this.

Thanks,
Sumukh
#
Use the cut() function to produce the interval categories and color
names in the data frame and then pass that variable to the col =
argument in the appropriate plot function. Something like

mydata$mycolors <- cut(mydata$value, c(-Inf, 1, 2, 3, Inf), label =
c('blue', 'green', 'yellow'))

Ask an abstract question, get an abstract answer...

HTH,
Dennis

On Tue, Jul 19, 2011 at 2:30 PM, Sumukh Sathnur
<sumukh.sathnur at gmail.com> wrote: