[R] how to save a heatmap.2 in png /jpeg /tiff

Rui Barradas ruipbarradas at sapo.pt
Sun Sep 9 21:23:35 CEST 2012


Hello,


Em 09-09-2012 18:36, Fred escreveu:
> hey Sarah,
> thanks for your help !!
>
> Of Course I put the second quote also (I forgot to put it on the last post).
> Sorry, I don't get the my.plot.code...

What Sarah meant is that you must put your.plot.code between the 
instructions that open and close the graphics device. This is example 1 
from the 'gplots::heatmap.2' help page, adapted.

# From ?gplots::heatmap.2
library(gplots)
data(mtcars)
x  <- as.matrix(mtcars)


# Plot nothing, but like Jeff said (suggested) it does something
# it opens the device and closes it
png(file = "myplot.png", bg = "transparent")
dev.off()  # 318 bytes file in current directory

# Plot an heatmap.2, example 1 in ?gplots::heatmap.2
png(file = "heatmap2.png")
heatmap.2(x)  ## default - dendrogram plotted and reordering done.
dev.off()  ## 10Kb file in current dir

# The same but to a jpeg graphics device
jpeg(file = "heatmap2.jpeg")
heatmap.2(x)  ## same as above
dev.off()  ## 46Kb file


Hope this helps,

Rui Barradas
> # I'm new in R and use it only to
> draw heatmaps right now.
> Well, I did forget the dev.off(). # but I got
> null device (1) # when quartz is turned off and when it's on I get : "
> quartz 2".
>
> But I don't have any files called "heatmap.2.png " on my computer.
> I really don't understand why I don't get anything !
>
> and when I do:
>> jpeg ("heatmap.jpg") # it works but I get only a 20kb picture which is
>> useless in my case (edit and work on it in photoshop)
> Fred
>
>
>
> --
> View this message in context: http://r.789695.n4.nabble.com/how-to-save-a-heatmap-2-in-png-jpeg-tiff-tp4642607p4642615.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> 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