Try this. It makes a copy of heatmap.2 whose scope is changed to
first look within heatmap.3 for functions like mtext. We redefine mtext
to intercept the text argument and change it appropriately. Then
we call our copy of heatmap.2. With this there is no need to change
the source of heatmap.2.
heatmap.3 <- function(...) {
environment(heatmap.2) <- environment()
mtext <- function(text, ...) {
if (text == "Value") text <- "Silly Value"
graphics::mtext(text, ...)
}
heatmap.2(...)
}
heatmap.3(as.matrix(heat),
keysize=1.2, dendrogram="none", trace="none", Colv = FALSE,
main = "Silly Data", labCol= NULL, margin=c(7,8))
On 7/19/07, Suzanne Matthews <[EMAIL PROTECTED]> wrote:
> Sorry, I just realized I didn't send this to the list! (See below)
>
> Thanks for all the help! All is working fine now.
>
> If anyone knows of a more straightforward way to change the "Value" string
> for the Key, please let me know (just to satisfy my curiosity). I got it to
> work by modifying the source code (specifically, "heatmap.2.R " in the
> gplots package).
>
> However, before, I didn't make the call
> source("heatmap.2.R")
>
> before I called
> source("mysillyheatmap.R")
>
> Making the additional call to " heatmap.2.R" fixed everything.
>
> Thanks again for all your help!
>
>
>
> On 7/19/07, Suzanne Matthews <[EMAIL PROTECTED]> wrote:
> >
> > Thank you all for your prompt replies! The check.names=FALSE parameter
> > fixed things entirely.
> >
> > One more question:
> >
> > Is there a straightforward way to modify the the "Values" string that
> > labels the key to a user-defined value? For example, let's say I want to
> > change "Values" to "Silly Values". So far, what I have found that I need to
> > do is actually go and change a static string in the source code. Is there a
> > more direct way?
> >
> > Also, after I make the source code change (in gplots package, file:
> > heatmap.2.R), how do I have R build from that? If I remember correctly, if
> > I put the new heatmap.2.R in my directory, R is supposed to check for
> > functions and such there before it goes and builds it from the main source
> > code base (located at /usr/bin/R). I am a touch confused on which directory
> > is "my" directory, where R will check first. I tried putting the modified
> > heatmap.2.R file in the directory that my script is, and where I initially
> > run R. But that didn't work!
> >
> > Is there anything that I should add to my R script that will force it to
> > read from that from my directory? If not, which directory should I place
> > this in?
> >
> > My OS is OS X, so I think Unix-based instructions will work.
> >
> > Thank you once again for your time and patience!
> >
> > Sincerely,
> > Suzanne
> >
> > On 7/18/07, Moshe Olshansky <[EMAIL PROTECTED]> wrote:
> > >
> > > I was right saying that my solution was not the best
> > > possible!
> > >
> > > --- Prof Brian Ripley <[EMAIL PROTECTED]> wrote:
> > >
> > > > 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
> > > > <[EMAIL PROTECTED]>
> > > > > 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]]
> > > > >>
> > > > >> ______________________________________________
> > > > >> [email protected] 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.
> > > > >>
> > > > >
> > > > > ______________________________________________
> > > > > [email protected] 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,
> > > > [EMAIL PROTECTED]
> > > > Professor of Applied Statistics,
> > > > http://www.stats.ox.ac.uk/~ripley/<http://www.stats.ox.ac.uk/%7Eripley/>
> > > > University of Oxford, Tel: +44 1865
> > > > 272861 (self)
> > > > 1 South Parks Road, +44 1865
> > > > 272866 (PA)
> > > > Oxford OX1 3TG, UK Fax: +44 1865
> > > > 272595
> > > >
> > >
> > >
> >
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> [email protected] 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.
>
______________________________________________
[email protected] 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.