geom_tile: fill vs. color

966 views
Skip to first unread message

Johannes Graumann

unread,
Jul 30, 2010, 9:20:05 AM7/30/10
to ggp...@googlegroups.com
Hi,

i have the following (using the attached data frame):

> library(ggplot2)
> load("df.Rd")
> heatMap <- ggplot(data=selectionFullSpectra,aes(x=Mass,y=ScanNumber))
> heatMap + geom_tile(aes(color=Intensity)) + labs(x="m/z (Th)")

From the documentation I would expect

> heatMap + geom_tile(aes(fill=Intensity)) + labs(x="m/z (Th)")

To work as well (desirable because of the legend formatting mainly), but it
doesn't plot anything ... what's wrong?

I also have "RetentionTime" as a "ScanNumber"-parallel unit and would
optimally like to display that on a second 'right-side' y-axis. Is there any
way to achieve that or a similar effect (despite of Hadleys newsgroup-
documented dislike)?

Thanks for any hint,
Joh

df.Rd
signature.asc

fernando

unread,
Jul 30, 2010, 3:02:11 PM7/30/10
to Johannes Graumann, ggp...@googlegroups.com
Hi Johannes,

My guess is the following. I think that because you have x (Mass) values
quite similar and because of the way tile widths are calculated; you don't
see nothing because tiles are excessively narrow.

library(ggplot2)
load("df.Rd")
ls()
selectionFullSpectra$width <- resolution(selectionFullSpectra$Mass, FALSE)
# width = 9.999999e-07
selectionFullSpectra$height <- resolution(selectionFullSpectra$ScanNumber,
FALSE)
# height = 9

heatMap <- ggplot(data=selectionFullSpectra,aes(x=Mass,y=ScanNumber))
heatMap + geom_tile(aes(fill=Intensity, width = width, height = height)) +
labs(x="m/z (Th)")
# equivalent to just heatMap + geom_tile(aes(fill=Intensity)) + labs(x="m/z
(Th)")

selectionFullSpectra$width <- 1
heatMap <- ggplot(data=selectionFullSpectra,aes(x=Mass,y=ScanNumber))
heatMap + geom_tile(aes(fill=Intensity, width = width, height = height)) +
labs(x="m/z (Th)")

I don't know how to estimate the minimum width or height in relation to plot
size that will be visible. Note that when you specify colour, you are seeing
the border of the tiles, e.g. lines, not tiles ... and I ignore to what
extent they can be overlapping among them ...

Considering this, and as a workaround, you can use
heatMap + geom_tile(aes(fill=Intensity, color = Intensity, width = width,
height = height)) + labs(x="m/z (Th)")

and you will obtain something similar to the desired result (the legend will
be ok, etc), but maybe it would be better to grid the data previously ...

To put two plots together I think the best option is to create two
independent plots and the use grid.arrange or vplayout. In this case I think
that facet_grid or facet_wrap would not be the best option given that the
ranges of your variables are quite different.

Hope this helps,
fernando

-----Mensaje original-----
De: ggp...@googlegroups.com [mailto:ggp...@googlegroups.com] En nombre de
Johannes Graumann
Enviado el: viernes, 30 de julio de 2010 15:20
Para: ggp...@googlegroups.com
Asunto: geom_tile: fill vs. color

Johannes Graumann

unread,
Aug 2, 2010, 5:22:36 AM8/2/10
to fernando, ggp...@googlegroups.com
Hi,

Thanks a lot for your insight. Playing around with "width" enables to plot
what I want.
The "two y-axes issue", persists, though. I REALLY would like to have that in
the same facet ... "RetentionTime" and "ScanNumber" really are diffferent
measures for the same beast, such as "paces" and "kilometers" might be ...
seems impossible in ggplto2, though ...

Joh

signature.asc
Reply all
Reply to author
Forward
0 new messages