[R] figure-definition and heatmap question
Paul Murrell
paul at stat.auckland.ac.nz
Fri Aug 24 13:21:36 CEST 2007
Hi
Antje wrote:
> There is no one who could help me with this?
>
> Antje schrieb:
>> Hello,
>>
>> I have two questions. I'd like to visualize data with a heatmap and I have the
>> following testcase:
>>
>> x <- rnorm(256)
>> nx <- x + abs(min(x))
>> nnx <- 255/max(nx) * nx
>> x <- matrix(nnx, 16, 16)
>> rownames(x) <- c("A","B","C","D","E","F","G","I","H","J","K","L","M","N","O","P")
>> par(fin=c(8.0,8.0))
>> cp <- colorRampPalette(c("white","springgreen","darkgreen"),space="Lab")
>> heatmap(x, Rowv = NA, Colv = NA, scale="none", col=cp(200))
>>
>> I defined the figure region to make sure that each position is a square. But
>> with these settings I get the following output (though it looks nice):
>> > x <- rnorm(256)
>> > nx <- x + abs(min(x))
>> > nnx <- 255/max(nx) * nx
>> > x <- matrix(nnx, 16, 16)
>> > rownames(x) <-
>> c("A","B","C","D","E","F","G","I","H","J","K","L","M","N","O","P")
>> > par(fin=c(8.0,8.0))
>> > cp <- colorRampPalette(c("white","springgreen","darkgreen"),space="Lab")
>> > heatmap(x, Rowv = NA, Colv = NA, scale="none", col=cp(200))
>> Fehler in par(op) : ungültiger Wert für den Grafikparameter "fig" spezifiziert
>> > par(fin=c(8.0,8.0))
>> > cp <- colorRampPalette(c("white","springgreen","darkgreen"),space="Lab")
>> > heatmap(x, Rowv = NA, Colv = NA, scale="none", col=cp(200))
>> Fehler in par(op) : ungültiger Wert für den Grafikparameter "fig" spezifiziert
>> > par()$fig
>> [1] 7.267443e-04 1.305448e-02 -2.862294e-17 9.876543e-01
>> > par()$fin
>> [1] 0.08834875 7.06790021
>>
>> Why do I get this error? Why does the parameters have these strange values
>> (though I set the fin parameter before...)
You are getting the error because you are setting the figure region to
be larger than the current device (typically 6 or 7 inches wide/high).
You SHOULD be getting the error when you try par(fin), BUT there is a
check missing in the C code, so what happens is that heatmap saves your
par settings and then tries to reset them (this is where par(op) comes
from), and because it saves BOTH par(fig) and par(fin) it resets both of
them, and when it resets par(fig) there IS a check on the values, the
values are larger than the current device and you get the error. Now,
because there is an error in resetting par(fig), that parameter is not
reset, so when you type par()$fin (or, equivalently, par("fin")) after
the heatmap() call, you get the last setting that heatmap() did, which
was from a layout inside heatmap, and so par("fig") is NOT what you set.
Finally, there is no point in setting par(fig) before heatmap()
because heatmap() is one of those functions that takes over the whole
device anyway, so your par(fig), even if it was valid, would have no
effect. If you want to make the heatmap() plot take up less of the
page, you could set outer margins (see par(oma)), e.g., ...
par(oma=rep(4, 4))
heatmap(x, Rowv = NA, Colv = NA, scale="none", col=cp(200))
If you want to make sure that each position in the heatmap is square, DO
NOTHING, because the layout that heatmap() sets up is using "respect" so
the image will be square no matter what you do.
Paul
>> And another question concerning the heatmap: May I force the funtion to plot A1
>> at the upper left corner instead of the lower left?
>>
>> I'll be glad about any idea how to solve these problems...
>>
>> Ciao,
>> Antje
>>
>> ______________________________________________
>> 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.
--
Dr Paul Murrell
Department of Statistics
The University of Auckland
Private Bag 92019
Auckland
New Zealand
64 9 3737599 x85392
paul at stat.auckland.ac.nz
http://www.stat.auckland.ac.nz/~paul/
More information about the R-help
mailing list