[R] saving heatmaps in graphical format that can be edited in graphic editor tools

Joshua Wiley jwiley.psych at gmail.com
Wed Sep 8 17:38:36 CEST 2010


Hi,

Without your data, we cannot actually reproduce your plot; however, if
you cannot read labels, there are generally three options.

1) Make the labels smaller (I have not used the function you used, so
I'm not sure exactly how one would)
2) Use fewer labels (if you need them all, this is a particularly
unattractive choice)
3) Make your graph bigger (this is the easiest though not always the best).

Sometimes, simply rotating the labels can help them not overlap too.

You can try changing the jpeg() line to:

jpeg("Heatmap.jpg", height=10+2/3, width=10+2/3, units="in", res=1200)

and keeping adding inches until things seem to work.  The downside, of
course, is that if it is every being printed, it may have to be
shrunk, but as long as it is an image, that will just make everything
smaller, not re-overlap the labels.

HTH,

Josh

On Wed, Sep 8, 2010 at 8:29 AM, Bhakti Dwivedi <bhakti.dwivedi at gmail.com> wrote:
> I generated a heatmap in R using the following commands:
>
>> mydata <- read.csv(file="Data.csv", header=TRUE, sep=",")
>> mydata <- mydata[rowSums(mydata[,-1]^2) >0, ]
>> rownames(mydata)=mydata$Name
>> mydata <- mydata[,2:253]
>> mydatamatrix <- data.matrix(mydata)
>> mydatascale <- t(scale(t(mydatamatrix)))
>> hr <- hclust(as.dist(1-cor(t(mydatascale), method="pearson")),
> method="complete")
>> hc <- hclust(as.dist(1-cor(mydatascale, method="spearman")),
> method="complete")
>> myclhr <- cutree(hr, h=max(hr$height)/2); mycolhr <- sample(rainbow(256));
>
>> myclhc <- cutree(hc, h=max(hc$height)/2); mycolhc <- sample(rainbow(256));
>
>> mycolhr <- mycolhr[as.vector(myclhr)];
>> mycolhc <- mycolhc[as.vector(myclhc)];
>> library("gplots")
>> library("RSvgDevice")
>> jpeg("Heatmap.jpg", height=6+2/3, width=6+2/3, units="in", res=1200)
>> heatmap.2(mydatamatrix, Rowv=as.dendrogram(hr), Colv=as.dendrogram(hc),
> dendrogram="both", scale="row", col=brewer.pal(3, "YlOrRd"), cexRow=0.01,
> cexCol=0.01,
>    trace="none", density.info="none", key=TRUE, keysize=1.5,
> margin=c(5,8),RowSideColor=mycolhr, ColSideColor=mycolhc)
>> dev.off()
>
>
> I would like to save the file in a graphical format that can be edited later
> in any image editing program (like corel).  is there a way to do this in R?
> Its a lot of data I plotted on heatmap (~ 300*600). The x and y labels are
> difficult to read.  I used cexRow = 0.01 and cexCol =0.01 with 1200
> resolution to save as jpeg file.  That helped but I can still hardly figure
> out the row labels.  I want to be able to read them to interpret the results
> and also to edit them with different font/color in corel and may be add
> other things that could be relevant to my work.  So, I guess my question
> here- is there a way I can make the labels readable in R itself or can I
> generate a list of the row and col labels (in the exact order as in figure)
> in a text file separately so I know the order and can try attaching it to
> heatmap in corel draw?
>
> any help will be appreciated!  Thanks
>
> BD
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> 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.
>



-- 
Joshua Wiley
Ph.D. Student, Health Psychology
University of California, Los Angeles
http://www.joshuawiley.com/



More information about the R-help mailing list