[R] simple, unidimensional heat map

Sarah Goslee sarah.goslee at gmail.com
Mon May 21 23:23:16 CEST 2012


Hi Dmitri,

On Mon, May 21, 2012 at 5:06 PM, Dimitri Liakhovitski
<dimitri.liakhovitski at gmail.com> wrote:
> I was wondering if someone could point in the direction of a package
> that could generate not heatmaps, but something like a unidimensional
> heat map.
> I might be mistaken, but it seems like image and heatmap are an
> overkill for such a simple task.

You don't have to use all the options. Why not use something like
image that does the heavy lifting for you?

> For example, if I have a data frame:
> x<-data.frame(myname=paste("value",1:10,sep=""),a=1:10,b=sample(1:10,10,replace=T))
>
> I'd like to create a chart (it's more of a table, actually) with one
> horizontal axis ("myname") and 2 rows of rectangles above it - one for
> "a" and one for "b". Such that the higher the value, the more intense
> the color of the rectangle (10 rectangles for 10 values).

Here's one approach:


image(as.matrix(x[,2:3]), xaxt="n", yaxt="n")
axis(1, seq(0, 1, length=10), x[,1])
axis(2, c(0, 1), colnames(x)[2:3])

Sarah

-- 
Sarah Goslee
http://www.functionaldiversity.org



More information about the R-help mailing list