[R] help with heatmap - how to remove annoying "X" before numeric values?

Prof Brian Ripley ripley at stats.ox.ac.uk
Thu Jul 19 05:40:43 CEST 2007


read.table('temp.txt', check.names = FALSE)

would be easier (and more general, since make.names can do more than 
prepend an 'X').

On Wed, 18 Jul 2007, Moshe Olshansky wrote:

> Hi Suzanne,
>
> My solution (which I am sure is not the best) would
> be:
>
>> heat <- read.table('temp.txt')
>> heat
>      X1905 X1910 X1950 X1992 X2011 X2020
> Gnat   0.08  0.29  0.29  0.37  0.39  0.43
> Snake  0.16  0.34  0.32  0.40  0.41  0.53
> Bat    0.40  0.54  0.52  0.60  0.60  0.63
> Cat    0.16  0.27  0.29  0.39  0.37  0.41
> Dog    0.43  0.54  0.52  0.61  0.60  0.62
> Lynx   0.50  0.57  0.54  0.59  0.50  0.59
>> a<-names(heat)
>> b<-strsplit(a,split="X")
>> w<-unlist(b)
>> w
> [1] ""     "1905" ""     "1910" ""     "1950" ""
> "1992" ""     "2011" ""     "2020"
>> z <- w[seq(2,length(w),by=2)]
>> z
> [1] "1905" "1910" "1950" "1992" "2011" "2020"
>> names(heat) <- z
>> heat
>      1905 1910 1950 1992 2011 2020
> Gnat  0.08 0.29 0.29 0.37 0.39 0.43
> Snake 0.16 0.34 0.32 0.40 0.41 0.53
> Bat   0.40 0.54 0.52 0.60 0.60 0.63
> Cat   0.16 0.27 0.29 0.39 0.37 0.41
> Dog   0.43 0.54 0.52 0.61 0.60 0.62
> Lynx  0.50 0.57 0.54 0.59 0.50 0.59
>>
>
> Regards,
>
> Moshe.
>
> --- Suzanne Matthews <suzanne.j.matthews at gmail.com>
> wrote:
>
>> Hello All,
>>
>> I have a simple question based on how things are
>> labeled on my heat map;
>> particularly, there is this annoying "X" that
>> appears before the numeric
>> value of all the labels of my columns.
>>
>> Let's say I have the following silly data, stored in
>> "temp.txt"
>>         1905    1910    1950    1992    2011    2020
>> Gnat    0.08    0.29    0.29    0.37    0.39    0.43
>> Snake   0.16    0.34    0.32    0.40    0.41    0.53
>> Bat     0.40    0.54    0.52    0.60    0.60    0.63
>> Cat     0.16    0.27    0.29    0.39    0.37    0.41
>> Dog     0.43    0.54    0.52    0.61    0.60    0.62
>> Lynx    0.50    0.57    0.54    0.59    0.5     0.59
>>
>> I use the following commands to generate my heatmap:
>> heat <- read.table('temp.txt')
>> x <- as.matrix(heat)
>>
>> heatmap.2(x, keysize=1.2, dendrogram="none",
>> trace="none", Colv = FALSE,
>> main = "Silly Data", labCol=
>> NULL, margin=c(7,8))
>>
>> This generates a very nice heatmap, but there is one
>> thing I have an issue
>> with: How do I get rid of the 'X' that seems to come
>> automatically before my
>> numeric column values? I just want those columns to
>> be labeled 1905, 1910,
>> 1950, and so on. I cannot find anything in the
>> heatmap.2 documentation that
>> suggests how I should do this.
>>
>> Thank you very much for your time, and patience in
>> reading this!
>>
>> Sincerely,
>> Suzanne
>>
>> 	[[alternative HTML version deleted]]
>>
>> ______________________________________________
>> R-help at stat.math.ethz.ch 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.
>>
>
> ______________________________________________
> R-help at stat.math.ethz.ch 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.
>

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595



More information about the R-help mailing list