Hi all, I used image.plot() to create a heat map of a matrix: as.matrix(read.table("Matrix.txt", sep="\t"))->x HeatBrk<-seq(5,25,2.5) MyCol= gray((7:0)/7) library(fields) image.plot(x, col=MyCol, breaks=HeatBrk, legend.shrink=0.3) dev.copy(device=pdf, file="HEAT4!.pdf", height=8, width=8) dev.off() There are a few things that I would like to do that I can't seem to find help with online: 1) Add axes to the bottom and left that go from 1:ncol(x) ; in this case, 104. Every time I try to add axes in some form or another they either go through the center of the image or do not show up at all. 2) Limit the scale of the legend from the minimum value to the maximum value that I assign a color to; as of now it goes from the minimum value (0) to the maximum value (300) but I would like it to stop at 25. 3) Rotate the resulting image 90 degrees to the right. Is there a generic way to do this? everything I have found online is case-specific and extremely complicated... I know this is a lot to ask, but I've been stuck on these for a few days and I can't seem to figure them out. Any help would be appreciated. Thanks in advance, Sumukh -------------- next part -------------- A non-text attachment was scrubbed... Name: HEAT4!.pdf Type: application/pdf Size: 49684 bytes Desc: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20110729/851ea5ad/attachment.pdf> -------------- next part -------------- An embedded and charset-unspecified text was scrubbed... Name: Matrix.txt URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20110729/851ea5ad/attachment.txt>
On Jul 29, 2011, at 6:38 PM, Sumukh Sathnur wrote:> Hi all, > > I used image.plot() to create a heat map of a matrix: > > as.matrix(read.table("Matrix.txt", sep="\t"))->x > HeatBrk<-seq(5,25,2.5) > MyCol= gray((7:0)/7) > library(fields) > image.plot(x, col=MyCol, breaks=HeatBrk, legend.shrink=0.3) > > dev.copy(device=pdf, file="HEAT4!.pdf", height=8, width=8) > dev.off() > > > > There are a few things that I would like to do that I can't seem to > find help with online: > > 1) Add axes to the bottom and left that go from 1:ncol(x) ; in this > case, 104. Every time I try to add axes in some form or another they > either go through the center of the image or do not show up at all. > > 2) Limit the scale of the legend from the minimum value to the > maximum value that I assign a color to; as of now it goes from the > minimum value (0) to the maximum value (300) but I would like it to > stop at 25. > > 3) Rotate the resulting image 90 degrees to the right. Is there a > generic way to do this? everything I have found online is case- > specific and extremely complicated...I don't have time to address the complte set of questions but wouldn't this last one be easily handled by reversing the x and y arguments to image.plot? -- David.> > I know this is a lot to ask, but I've been stuck on these for a few > days and I can't seem to figure them out. Any help would be > appreciated. > > > Thanks in advance, > Sumukh > > <HEAT4!.pdf><Matrix.txt>______________________________________________ > 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.David Winsemius, MD West Hartford, CT
Jim, Thanks for the response! It turns out that using color2D.matplot actually eliminates my need to rotate the matrix at all. However, I'm not quite sure I understand the arguments for assigning colors to the cells. Using image and image.plot, I used col= and breaks= to define a certain color to a specific range of values (in my case, shades of gray). However, I just can't figure out how to do this in color2D.matplot. I mostly just don't really understand cs1 cs2 and cs3, and I'm more or less lost on how to reproduce the same sort of plot. I've only been using R for about a month, so I hope that explains my lack of knowledge...if you could help me out it would be much appreciated. Thanks, Sumukh On 8/1/2011 2:30 AM, Jim Lemon wrote:> On 07/30/2011 08:38 AM, Sumukh Sathnur wrote: >> Hi all, >> >> I used image.plot() to create a heat map of a matrix: >> >> as.matrix(read.table("Matrix.txt", sep="\t"))->x >> HeatBrk<-seq(5,25,2.5) >> MyCol= gray((7:0)/7) >> library(fields) >> image.plot(x, col=MyCol, breaks=HeatBrk, legend.shrink=0.3) >> >> dev.copy(device=pdf, file="HEAT4!.pdf", height=8, width=8) >> dev.off() >> >> >> >> There are a few things that I would like to do that I can't seem to find >> help with online: >> >> 1) Add axes to the bottom and left that go from 1:ncol(x) ; in this >> case, 104. Every time I try to add axes in some form or another they >> either go through the center of the image or do not show up at all. >> >> 2) Limit the scale of the legend from the minimum value to the maximum >> value that I assign a color to; as of now it goes from the minimum value >> (0) to the maximum value (300) but I would like it to stop at 25. >> >> 3) Rotate the resulting image 90 degrees to the right. Is there a >> generic way to do this? everything I have found online is case-specific >> and extremely complicated... >> > Hi Sumukh, > 1) Have a look at color2D.matplot in the plotrix package. > 2) Have a look at color.legend in the plotrix package > 3) Use the t (transpose) command > > Jim >-------------- next part -------------- An embedded and charset-unspecified text was scrubbed... Name: Matrix.txt URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20110804/8be0a8fd/attachment.txt>