Creating a simple 1-row heatmap

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Creating a simple 1-row heatmap

Justin Fincher
Howdy,
   I am trying to make a simple monochrome heatmap from 1 row of data.
 Essentially, I just want a long bar where black represents the max value in
the data, white is the minimum, and all values in between are interpolated
appropriately.  I have tried using heatmap and heatmap.2, but both have
issues. heatmap seems to be restricted to only drawing a square plot, and
this data requires a long, thin plot (e.g. 50px tall by 3000 px wide). For
heatmap.2, the plots will draw the dimensions I prefer, but when I do a
small sample the coloring seems to not correlate with the data even though I
have Rowv and Colv both set to FALSE.  Any recommendations about the best
way to make a clean, simple heatmap from a single array of positive integers
would be greatly appreciated.

- Fincher

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: Creating a simple 1-row heatmap

Michael Weylandt
Would the image() function do what you need?

n = sample(1:50,25);
g = gray(n/max(n)) # set up color palate
g = rev(g) # reverse so max is black instead of white
image(as.matrix(n),col=g) # Requires a matrix input

I think you should be able to handle axes/ labels/ etc as normal:

image(as.matrix(n),col=g,xaxt="n",yaxt="n",main="Very Important Data")

If you adjust the aspect ratio, you can get your desired bar shape/size.

Michael Weylandt

On Mon, Aug 8, 2011 at 5:10 PM, Justin Fincher <[hidden email]> wrote:

> Howdy,
>   I am trying to make a simple monochrome heatmap from 1 row of data.
>  Essentially, I just want a long bar where black represents the max value
> in
> the data, white is the minimum, and all values in between are interpolated
> appropriately.  I have tried using heatmap and heatmap.2, but both have
> issues. heatmap seems to be restricted to only drawing a square plot, and
> this data requires a long, thin plot (e.g. 50px tall by 3000 px wide). For
> heatmap.2, the plots will draw the dimensions I prefer, but when I do a
> small sample the coloring seems to not correlate with the data even though
> I
> have Rowv and Colv both set to FALSE.  Any recommendations about the best
> way to make a clean, simple heatmap from a single array of positive
> integers
> would be greatly appreciated.
>
> - Fincher
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: Creating a simple 1-row heatmap

Justin Fincher
Thank you for that.  I had to do some tweaking, but I managed to get it
working.  In case anyone wants to do something similar, here's my solution.

n = sample(1:50,25)
g = gray(1-(n/max(n))) # the subtraction from 1 reverses the colors.  rev()
just reverses the order of the colors.
image(as.matrix(seq(1:25)),col=g) # if I passed it n, it drew the colors all
over the place.  This draws them in order so that filling in with g aligns
to the original data.

Thank you again for your help.

- Fincher


On Mon, Aug 8, 2011 at 18:01, R. Michael Weylandt <
[hidden email]> wrote:

> Would the image() function do what you need?
>
> n = sample(1:50,25);
> g = gray(n/max(n)) # set up color palate
> g = rev(g) # reverse so max is black instead of white
> image(as.matrix(n),col=g) # Requires a matrix input
>
> I think you should be able to handle axes/ labels/ etc as normal:
>
> image(as.matrix(n),col=g,xaxt="n",yaxt="n",main="Very Important Data")
>
> If you adjust the aspect ratio, you can get your desired bar shape/size.
>
> Michael Weylandt
>
> On Mon, Aug 8, 2011 at 5:10 PM, Justin Fincher <[hidden email]> wrote:
>
>> Howdy,
>>   I am trying to make a simple monochrome heatmap from 1 row of data.
>>  Essentially, I just want a long bar where black represents the max value
>> in
>> the data, white is the minimum, and all values in between are interpolated
>> appropriately.  I have tried using heatmap and heatmap.2, but both have
>> issues. heatmap seems to be restricted to only drawing a square plot, and
>> this data requires a long, thin plot (e.g. 50px tall by 3000 px wide). For
>> heatmap.2, the plots will draw the dimensions I prefer, but when I do a
>> small sample the coloring seems to not correlate with the data even though
>> I
>> have Rowv and Colv both set to FALSE.  Any recommendations about the best
>> way to make a clean, simple heatmap from a single array of positive
>> integers
>> would be greatly appreciated.
>>
>> - Fincher
>>
>>        [[alternative HTML version deleted]]
>>
>> ______________________________________________
>> [hidden email] mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>
>
> --
> This message has been scanned for viruses and
> dangerous content by *MailScanner* <http://www.mailscanner.info/>, and is
> believed to be clean.

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.