[R] heatmap for plotting categorical matrix

Yihui Xie xie at yihui.name
Tue Oct 25 03:48:35 CEST 2011


not sure about gplots, but the one in base R should work well if you
specify the scaling method to be 'none':

heatmap(a4[1:40, ],  Rowv=NA, Colv=NA, col=c("grey", "blue", "purple",
"red"), scale='none')

Regards,
Yihui
--
Yihui Xie <xieyihui at gmail.com>
Phone: 515-294-2465 Web: http://yihui.name
Department of Statistics, Iowa State University
2215 Snedecor Hall, Ames, IA



On Mon, Oct 24, 2011 at 6:07 PM, Weiwei Shi <helprhelp at gmail.com> wrote:
> Hi there,
>
> I have a matrix like this:
>
>> a4[1:20, 1:5]
>           194 211 294 314 315
> GO:0000003   1   1   1   1   1
> GO:0000072   0   0   0   0   0
> GO:0000076   1   0   0   0   0
> GO:0000082   1   3   1   1   1
> GO:0000083   1   0   0   0   1
> GO:0000086   0   1   0   1   1
> GO:0000114   0   0   0   0   0
> GO:0000115   0   0   0   0   0
> GO:0000117   0   0   0   0   0
> GO:0000160   0   0   1   0   0
> GO:0000212   0   0   0   0   0
> GO:0000216   1   0   0   1   0
> GO:0000226   1   0   1   0   0
> GO:0000278   1   1   1   2   1
> GO:0000320   0   0   0   0   0
> GO:0000710   0   0   0   0   0
> GO:0000768   0   0   0   0   0
> GO:0000819   1   0   0   1   1
> GO:0000910   1   0   0   3   0
> GO:0000917   0   0   0   0   0
>
> I wanted to plot a heatmap to assign "grey" to 0, "blue" to 1, "purple" to
> 2, and "red" to 3. I did not some trials and found some problems like this:
>
> When the row is all zero, there could be a white bar in the middle of the
> heatmap though I did not assign "white" to any value.
>
> Or some row believes "grey" as 0 while some rows believes "blue" as "0".
>
> Did I make some mistake here?
>
> library(gplots)
>
> heatmap.2(a4[1:40,],  Rowv=NA, Colv=NA, col=c("grey", "blue", "purple",
> "red"), trace="none")
>
>
> Thanks,
>
> Weiwei
> --
> Weiwei Shi, Ph.D
> Research Scientist
>
>
> "Did you always know?"
> "No, I did not. But I believed..."
> ---Matrix III
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org 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.
>



More information about the R-help mailing list