ggplots2 - heatmap2 colour labels
1
0
Entering edit mode
@paolo-kunderfranco-5158
Last seen 6.8 years ago
Dear All, I would like to add colours to my heatmap, for instance I have a set of genes, some are up-regulated and some are down-regulated example this is my data.matrix >x Pfdn5 11.73 1.000 Aqp1 9.25 1.000 Lims2 11.15 1.000 Chrac1 1.00 13.990 Sdhb 1.00 7.460 Phpt1 8.28 1.000 Dhrs7c 10.93 1.000 Mrpl30 1.00 7.690 Mrps35 11.15 1.000 Mlf1 18.50 1.000 Atp5h 9.29 1.000 heatmap.2(x, Colv=F, Rowv=F,cexCol=0.5, main="test", cexRow=0.3,scale="row", col=greenred(75), key=F, trace="none") I would like to plot the first 3 labels in red and the rest in blue, is it possible with heatmap.2 function? Thanks, Paolo
• 2.5k views
ADD COMMENT
0
Entering edit mode
@james-w-macdonald-5106
Last seen 1 hour ago
United States
Hi Paolo, First, I am assuming here that your subject line is incorrect, and that you are talking about the heatmap.2() function in gplots, not something that is in ggplot2. On 10/2/2012 8:56 AM, Paolo Kunderfranco wrote: > Dear All, > I would like to add colours to my heatmap, for instance I have a set > of genes, some are up-regulated and some are down-regulated > > example > this is my data.matrix >> x > Pfdn5 11.73 1.000 > Aqp1 9.25 1.000 > Lims2 11.15 1.000 > Chrac1 1.00 13.990 > Sdhb 1.00 7.460 > Phpt1 8.28 1.000 > Dhrs7c 10.93 1.000 > Mrpl30 1.00 7.690 > Mrps35 11.15 1.000 > Mlf1 18.50 1.000 > Atp5h 9.29 1.000 > > > heatmap.2(x, Colv=F, Rowv=F,cexCol=0.5, main="test", > cexRow=0.3,scale="row", col=greenred(75), key=F, trace="none") > > > > I would like to plot the first 3 labels in red and the rest in blue, > is it possible with heatmap.2 function? Not easily. You would have to modify the code to heatmap.2() to accept the two color arguments, as well as calling axis() twice. The relevant part of heatmap.2() looks like this: if (!invalid(na.color) & anyis.na(x))) { mmat <- ifelseis.na(x), 1, NA) image(1:nc, 1:nr, mmat, axes = FALSE, xlab = "", ylab = "", col = na.color, add = TRUE) } axis(1, 1:nc, labels = labCol, las = 2, line = -0.5, tick = 0, cex.axis = cexCol) if (!is.null(xlab)) mtext(xlab, side = 1, line = margins[1] - 1.25) axis(4, iy, labels = labRow, las = 2, line = -0.5, tick = 0, cex.axis = cexRow) Where the two calls to axis() put the horizontal and vertical axis labels on. In particular, the last axis() call does the row names. The problem here is that you can only pass a single color for the axis labels, so you will have to call axis(4, <otherstuff>) twice to do the two different colors. So you will have to change that last call to do just the first 3, with the col.axis argument set to "red", and then the remaining labels with the col.axis argument set to "blue". Something like (untested): axis(4, iy[1:3], labRow[1:3], las=2, line=-0.5, tick=0,cex.axis=cexRow, col.axis="red") axis(4, iy[-c(1:3)], labRow[-c(1:3)], las=2, line=-0.5, tick=0,cex.axis=cexRow, col.axis="blue") I'll leave the rest of it up to you. You might need to google things like 'R modify code' or some such if you don't know how to extract and modify existing code in R. Best, Jim > Thanks, > Paolo > > _______________________________________________ > Bioconductor mailing list > Bioconductor at r-project.org > https://stat.ethz.ch/mailman/listinfo/bioconductor > Search the archives: http://news.gmane.org/gmane.science.biology.informatics.conductor -- James W. MacDonald, M.S. Biostatistician University of Washington Environmental and Occupational Health Sciences 4225 Roosevelt Way NE, # 100 Seattle WA 98105-6099
ADD COMMENT
0
Entering edit mode
Great! Thanks a lot is now working fine! cheers, paolo 2012/10/2 James W. MacDonald <jmacdon at="" uw.edu="">: > Hi Paolo, > > First, I am assuming here that your subject line is incorrect, and that you > are talking about the heatmap.2() function in gplots, not something that is > in ggplot2. > > > On 10/2/2012 8:56 AM, Paolo Kunderfranco wrote: >> >> Dear All, >> I would like to add colours to my heatmap, for instance I have a set >> of genes, some are up-regulated and some are down-regulated >> >> example >> this is my data.matrix >>> >>> x >> >> Pfdn5 11.73 1.000 >> Aqp1 9.25 1.000 >> Lims2 11.15 1.000 >> Chrac1 1.00 13.990 >> Sdhb 1.00 7.460 >> Phpt1 8.28 1.000 >> Dhrs7c 10.93 1.000 >> Mrpl30 1.00 7.690 >> Mrps35 11.15 1.000 >> Mlf1 18.50 1.000 >> Atp5h 9.29 1.000 >> >> >> heatmap.2(x, Colv=F, Rowv=F,cexCol=0.5, main="test", >> cexRow=0.3,scale="row", col=greenred(75), key=F, trace="none") >> >> >> >> I would like to plot the first 3 labels in red and the rest in blue, >> is it possible with heatmap.2 function? > > > Not easily. You would have to modify the code to heatmap.2() to accept the > two color arguments, as well as calling axis() twice. The relevant part of > heatmap.2() looks like this: > > if (!invalid(na.color) & anyis.na(x))) { > mmat <- ifelseis.na(x), 1, NA) > image(1:nc, 1:nr, mmat, axes = FALSE, xlab = "", ylab = "", > col = na.color, add = TRUE) > } > axis(1, 1:nc, labels = labCol, las = 2, line = -0.5, tick = 0, > cex.axis = cexCol) > if (!is.null(xlab)) > mtext(xlab, side = 1, line = margins[1] - 1.25) > axis(4, iy, labels = labRow, las = 2, line = -0.5, tick = 0, > cex.axis = cexRow) > > Where the two calls to axis() put the horizontal and vertical axis labels > on. In particular, the last axis() call does the row names. > > The problem here is that you can only pass a single color for the axis > labels, so you will have to call axis(4, <otherstuff>) twice to do the two > different colors. So you will have to change that last call to do just the > first 3, with the col.axis argument set to "red", and then the remaining > labels with the col.axis argument set to "blue". Something like (untested): > > axis(4, iy[1:3], labRow[1:3], las=2, line=-0.5, tick=0,cex.axis=cexRow, > col.axis="red") > axis(4, iy[-c(1:3)], labRow[-c(1:3)], las=2, line=-0.5, > tick=0,cex.axis=cexRow, col.axis="blue") > > I'll leave the rest of it up to you. You might need to google things like 'R > modify code' or some such if you don't know how to extract and modify > existing code in R. > > Best, > > Jim > > >> Thanks, >> Paolo >> >> _______________________________________________ >> Bioconductor mailing list >> Bioconductor at r-project.org >> https://stat.ethz.ch/mailman/listinfo/bioconductor >> Search the archives: >> http://news.gmane.org/gmane.science.biology.informatics.conductor > > > -- > James W. MacDonald, M.S. > Biostatistician > University of Washington > Environmental and Occupational Health Sciences > 4225 Roosevelt Way NE, # 100 > Seattle WA 98105-6099 >
ADD REPLY

Login before adding your answer.

Traffic: 843 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6