different color for a subset of points on heatmap
1
0
Entering edit mode
@marek-piatek-bi-3927
Last seen 10.2 years ago
Hi all, Is there any way to use different color on a subset of points on a heatmap? I just would like see a particular set of genes standing out from the rest. Thank you, Marek
• 1.8k views
ADD COMMENT
0
Entering edit mode
@francoissusmcgillca-3904
Last seen 10.2 years ago
HI Marek, The easiest way I can think of: One would be give those genes a different set of values. So if all your data is between -5 to 5, have the special genes from say 10 to 20. Then you can send it a set of colors that covers everything. Here's an example where half is positive and half is negative. You can see the transparent colors in half of the columns as opposed to the non-transparent ones otherwise. > heatmap(matrix(c(1,runif(49),-1,-runif(49)),10),col=cbind(heat.color s(20,alpha=0.25),heat.colors(20,alpha=1))) You'll need to be a bit careful to get the colors to match. I put the 1 and -1 to make sure that we cover the range and the colors and and values match. HTH, Francois On Jun 18, 2010, at 6:38 AM, marek piatek (BI) wrote: > Hi all, > > Is there any way to use different color on a subset of points on a heatmap? > I just would like see a particular set of genes standing out from the rest. > > Thank you, > Marek > > _______________________________________________ > Bioconductor mailing list > Bioconductor at stat.math.ethz.ch > https://stat.ethz.ch/mailman/listinfo/bioconductor > Search the archives: http://news.gmane.org/gmane.science.biology.informatics.conductor
ADD COMMENT
0
Entering edit mode
Hi Francois and all, Thanks for your advice. However if I will give my subset different values they will get clustered in different way - which is not what I want. Your approach is good if I wouldn't be using clustering. And also the subset I would like to use different colour for is a subset of larger population (its min and max values are within the larger set). Any other ideas? Thank you in advance, Marek -----Original Message----- From: Francois Pepin [mailto:francois@sus.mcgill.ca] Sent: 18 June 2010 20:41 To: marek piatek (BI) Cc: bioconductor at stat.math.ethz.ch Subject: Re: [BioC] different color for a subset of points on heatmap HI Marek, The easiest way I can think of: One would be give those genes a different set of values. So if all your data is between -5 to 5, have the special genes from say 10 to 20. Then you can send it a set of colors that covers everything. Here's an example where half is positive and half is negative. You can see the transparent colors in half of the columns as opposed to the non-transparent ones otherwise. > heatmap(matrix(c(1,runif(49),-1,-runif(49)),10),col=cbind(heat.color s(20,alpha=0.25),heat.colors(20,alpha=1))) You'll need to be a bit careful to get the colors to match. I put the 1 and -1 to make sure that we cover the range and the colors and and values match. HTH, Francois On Jun 18, 2010, at 6:38 AM, marek piatek (BI) wrote: > Hi all, > > Is there any way to use different color on a subset of points on a heatmap? > I just would like see a particular set of genes standing out from the rest. > > Thank you, > Marek > > _______________________________________________ > Bioconductor mailing list > Bioconductor at stat.math.ethz.ch > https://stat.ethz.ch/mailman/listinfo/bioconductor > Search the archives: http://news.gmane.org/gmane.science.biology.informatics.conductor
ADD REPLY
0
Entering edit mode
On Mon, Jun 21, 2010 at 4:24 AM, marek piatek (BI) <marek.piatek@bbsrc.ac.uk> wrote: > Hi Francois and all, > > Thanks for your advice. However if I will give my subset different values > they will get clustered in different way - which is not what I want. Your > approach is good if I wouldn't be using clustering. > And also the subset I would like to use different colour for is a subset of > larger population (its min and max values are within the larger set). > > If you can use heatmap.2, take a look at the rowsep (or colsep) arguments to set off a block of genes. Also, you could consider adding RowSideColors to your gene of interest. Sean > Any other ideas? > > Thank you in advance, > Marek > > > -----Original Message----- > From: Francois Pepin [mailto:francois@sus.mcgill.ca] > Sent: 18 June 2010 20:41 > To: marek piatek (BI) > Cc: bioconductor@stat.math.ethz.ch > Subject: Re: [BioC] different color for a subset of points on heatmap > > HI Marek, > > The easiest way I can think of: > > One would be give those genes a different set of values. So if all your > data is between -5 to 5, have the special genes from say 10 to 20. Then you > can send it a set of colors that covers everything. > > Here's an example where half is positive and half is negative. You can see > the transparent colors in half of the columns as opposed to the > non-transparent ones otherwise. > > > > heatmap(matrix(c(1,runif(49),-1,-runif(49)),10),col=cbind(heat.color s(20,alpha=0.25),heat.colors(20,alpha=1))) > > You'll need to be a bit careful to get the colors to match. I put the 1 and > -1 to make sure that we cover the range and the colors and and values match. > > HTH, > > Francois > > On Jun 18, 2010, at 6:38 AM, marek piatek (BI) wrote: > > > Hi all, > > > > Is there any way to use different color on a subset of points on a > heatmap? > > I just would like see a particular set of genes standing out from the > rest. > > > > Thank you, > > Marek > > > > _______________________________________________ > > Bioconductor mailing list > > Bioconductor@stat.math.ethz.ch > > https://stat.ethz.ch/mailman/listinfo/bioconductor > > Search the archives: > http://news.gmane.org/gmane.science.biology.informatics.conductor > > _______________________________________________ > Bioconductor mailing list > Bioconductor@stat.math.ethz.ch > https://stat.ethz.ch/mailman/listinfo/bioconductor > Search the archives: > http://news.gmane.org/gmane.science.biology.informatics.conductor > [[alternative HTML version deleted]]
ADD REPLY
0
Entering edit mode
You could perhaps change the values in the ordered matrix resulting from the clustering. Suppose you cluster your rows and columns with hclust function from cluster package. Your initial data matrix is 'mat'. rows.diss <- dist(mat) # dissimilarity between rows cols.diss <- dist(t(mat)) # dissimilarity between cols rows.clust <- hclust(rows.diss) cols.clust <- hclust(cols.diss) ordered.matrix <- mat[rows.clust$order,cols.clust$order] Then you change the values of the genes of interest and then use image() to plot the result. AF On 21 June 2010 10:24, marek piatek (BI) <marek.piatek@bbsrc.ac.uk> wrote: > Hi Francois and all, > > Thanks for your advice. However if I will give my subset different values > they will get clustered in different way - which is not what I want. Your > approach is good if I wouldn't be using clustering. > And also the subset I would like to use different colour for is a subset of > larger population (its min and max values are within the larger set). > > Any other ideas? > > Thank you in advance, > Marek > > > -----Original Message----- > From: Francois Pepin [mailto:francois@sus.mcgill.ca] > Sent: 18 June 2010 20:41 > To: marek piatek (BI) > Cc: bioconductor@stat.math.ethz.ch > Subject: Re: [BioC] different color for a subset of points on heatmap > > HI Marek, > > The easiest way I can think of: > > One would be give those genes a different set of values. So if all your > data is between -5 to 5, have the special genes from say 10 to 20. Then you > can send it a set of colors that covers everything. > > Here's an example where half is positive and half is negative. You can see > the transparent colors in half of the columns as opposed to the > non-transparent ones otherwise. > > > > heatmap(matrix(c(1,runif(49),-1,-runif(49)),10),col=cbind(heat.color s(20,alpha=0.25),heat.colors(20,alpha=1))) > > You'll need to be a bit careful to get the colors to match. I put the 1 and > -1 to make sure that we cover the range and the colors and and values match. > > HTH, > > Francois > > On Jun 18, 2010, at 6:38 AM, marek piatek (BI) wrote: > > > Hi all, > > > > Is there any way to use different color on a subset of points on a > heatmap? > > I just would like see a particular set of genes standing out from the > rest. > > > > Thank you, > > Marek > > > > _______________________________________________ > > Bioconductor mailing list > > Bioconductor@stat.math.ethz.ch > > https://stat.ethz.ch/mailman/listinfo/bioconductor > > Search the archives: > http://news.gmane.org/gmane.science.biology.informatics.conductor > > _______________________________________________ > Bioconductor mailing list > Bioconductor@stat.math.ethz.ch > https://stat.ethz.ch/mailman/listinfo/bioconductor > Search the archives: > http://news.gmane.org/gmane.science.biology.informatics.conductor > [[alternative HTML version deleted]]
ADD REPLY
0
Entering edit mode
That does not make it easy to plot the dendrograms along with the image. But you can use the Rowv and Colv arguments of heatmap to accomplish the same thing. Here is a complete example: #################### begin example ############### set.seed(183426) # for reproducible simulation M <- 500 # genes N <- 30 # samples dataset <- matrix(rnorm(M*N), ncol=N, nrow=M) # simulate data row.hc <- hclust(dist(dataset)) # simulate special genes in one branch; only for example purposes special.genes <- which(cutree(row.hc, k=2) == 2) row.hc <- as.dendrogram(row.hc) col.hc <- as.dendrogram(hclust(dist(t(dataset)))) K <- 3 # cutoff in standardized units # standardize data and truncate symmetrically displaydata <- t(scale(t(dataset))) displaydata[displaydata > K] <- K displaydata[displaydata < -K] <- -K # shift into different ranges; first ordinary genes displaydata <- displaydata + K # now lives in [0, 2K] # then shift the special genes into a new range displaydata[special.genes,] <- displaydata[special.genes,] - 2*K # pick the paitrs of colormaps you want colorset <- cbind(topo.colors(20,alpha=0.75), heat.colors(20,alpha=1)) # use heatmap as a display tool, not a clustering tool heatmap(displaydata, scale='none', zlim=c(-2*K, 2*K), Rowv=row.hc, Colv=col.hc, col=colorset) ###################### end example ################# Anthony Ferrari wrote: > You could perhaps change the values in the ordered matrix resulting from the > clustering. > > Suppose you cluster your rows and columns with hclust function from cluster > package. Your initial data matrix is 'mat'. > > rows.diss <- dist(mat) # dissimilarity between rows > cols.diss <- dist(t(mat)) # dissimilarity between cols > > rows.clust <- hclust(rows.diss) > cols.clust <- hclust(cols.diss) > > ordered.matrix <- mat[rows.clust$order,cols.clust$order] > > Then you change the values of the genes of interest and then use image() to > plot the result. > > AF > > > > On 21 June 2010 10:24, marek piatek (BI) <marek.piatek at="" bbsrc.ac.uk=""> wrote: > > >> Hi Francois and all, >> >> Thanks for your advice. However if I will give my subset different values >> they will get clustered in different way - which is not what I want. Your >> approach is good if I wouldn't be using clustering. >> And also the subset I would like to use different colour for is a subset of >> larger population (its min and max values are within the larger set). >> >> Any other ideas? >> >> Thank you in advance, >> Marek >> >> >> -----Original Message----- >> From: Francois Pepin [mailto:francois at sus.mcgill.ca] >> Sent: 18 June 2010 20:41 >> To: marek piatek (BI) >> Cc: bioconductor at stat.math.ethz.ch >> Subject: Re: [BioC] different color for a subset of points on heatmap >> >> HI Marek, >> >> The easiest way I can think of: >> >> One would be give those genes a different set of values. So if all your >> data is between -5 to 5, have the special genes from say 10 to 20. Then you >> can send it a set of colors that covers everything. >> >> Here's an example where half is positive and half is negative. You can see >> the transparent colors in half of the columns as opposed to the >> non-transparent ones otherwise. >> >> >> heatmap(matrix(c(1,runif(49),-1,-runif(49)),10),col=cbind(heat.colo rs(20,alpha=0.25),heat.colors(20,alpha=1))) >> >> You'll need to be a bit careful to get the colors to match. I put the 1 and >> -1 to make sure that we cover the range and the colors and and values match. >> >> HTH, >> >> Francois >> >> On Jun 18, 2010, at 6:38 AM, marek piatek (BI) wrote: >> >> >>> Hi all, >>> >>> Is there any way to use different color on a subset of points on a >>> >> heatmap? >> >>> I just would like see a particular set of genes standing out from the >>> >> rest. >> >>> Thank you, >>> Marek >>> >>> _______________________________________________ >>> Bioconductor mailing list >>> Bioconductor at stat.math.ethz.ch >>> https://stat.ethz.ch/mailman/listinfo/bioconductor >>> Search the archives: >>> >> http://news.gmane.org/gmane.science.biology.informatics.conductor >> >> _______________________________________________ >> Bioconductor mailing list >> Bioconductor at stat.math.ethz.ch >> https://stat.ethz.ch/mailman/listinfo/bioconductor >> Search the archives: >> http://news.gmane.org/gmane.science.biology.informatics.conductor >> >> > > [[alternative HTML version deleted]] > > _______________________________________________ > Bioconductor mailing list > Bioconductor at stat.math.ethz.ch > https://stat.ethz.ch/mailman/listinfo/bioconductor > Search the archives: http://news.gmane.org/gmane.science.biology.informatics.conductor >
ADD REPLY
0
Entering edit mode
Hi all, Thanks for all the responses! I think that Kevin's example illustrates the best what I would like to do. Thanks once again, Marek -----Original Message----- From: Kevin Coombes [mailto:kevin.r.coombes@gmail.com] Sent: 21 June 2010 16:54 To: Anthony Ferrari Cc: marek piatek (BI); bioconductor at stat.math.ethz.ch Subject: Re: [BioC] different color for a subset of points on heatmap That does not make it easy to plot the dendrograms along with the image. But you can use the Rowv and Colv arguments of heatmap to accomplish the same thing. Here is a complete example: #################### begin example ############### set.seed(183426) # for reproducible simulation M <- 500 # genes N <- 30 # samples dataset <- matrix(rnorm(M*N), ncol=N, nrow=M) # simulate data row.hc <- hclust(dist(dataset)) # simulate special genes in one branch; only for example purposes special.genes <- which(cutree(row.hc, k=2) == 2) row.hc <- as.dendrogram(row.hc) col.hc <- as.dendrogram(hclust(dist(t(dataset)))) K <- 3 # cutoff in standardized units # standardize data and truncate symmetrically displaydata <- t(scale(t(dataset))) displaydata[displaydata > K] <- K displaydata[displaydata < -K] <- -K # shift into different ranges; first ordinary genes displaydata <- displaydata + K # now lives in [0, 2K] # then shift the special genes into a new range displaydata[special.genes,] <- displaydata[special.genes,] - 2*K # pick the paitrs of colormaps you want colorset <- cbind(topo.colors(20,alpha=0.75), heat.colors(20,alpha=1)) # use heatmap as a display tool, not a clustering tool heatmap(displaydata, scale='none', zlim=c(-2*K, 2*K), Rowv=row.hc, Colv=col.hc, col=colorset) ###################### end example ################# Anthony Ferrari wrote: > You could perhaps change the values in the ordered matrix resulting from the > clustering. > > Suppose you cluster your rows and columns with hclust function from cluster > package. Your initial data matrix is 'mat'. > > rows.diss <- dist(mat) # dissimilarity between rows > cols.diss <- dist(t(mat)) # dissimilarity between cols > > rows.clust <- hclust(rows.diss) > cols.clust <- hclust(cols.diss) > > ordered.matrix <- mat[rows.clust$order,cols.clust$order] > > Then you change the values of the genes of interest and then use image() to > plot the result. > > AF > > > > On 21 June 2010 10:24, marek piatek (BI) <marek.piatek at="" bbsrc.ac.uk=""> wrote: > > >> Hi Francois and all, >> >> Thanks for your advice. However if I will give my subset different values >> they will get clustered in different way - which is not what I want. Your >> approach is good if I wouldn't be using clustering. >> And also the subset I would like to use different colour for is a subset of >> larger population (its min and max values are within the larger set). >> >> Any other ideas? >> >> Thank you in advance, >> Marek >> >> >> -----Original Message----- >> From: Francois Pepin [mailto:francois at sus.mcgill.ca] >> Sent: 18 June 2010 20:41 >> To: marek piatek (BI) >> Cc: bioconductor at stat.math.ethz.ch >> Subject: Re: [BioC] different color for a subset of points on heatmap >> >> HI Marek, >> >> The easiest way I can think of: >> >> One would be give those genes a different set of values. So if all your >> data is between -5 to 5, have the special genes from say 10 to 20. Then you >> can send it a set of colors that covers everything. >> >> Here's an example where half is positive and half is negative. You can see >> the transparent colors in half of the columns as opposed to the >> non-transparent ones otherwise. >> >> >> heatmap(matrix(c(1,runif(49),-1,-runif(49)),10),col=cbind(heat.colo rs(20,alpha=0.25),heat.colors(20,alpha=1))) >> >> You'll need to be a bit careful to get the colors to match. I put the 1 and >> -1 to make sure that we cover the range and the colors and and values match. >> >> HTH, >> >> Francois >> >> On Jun 18, 2010, at 6:38 AM, marek piatek (BI) wrote: >> >> >>> Hi all, >>> >>> Is there any way to use different color on a subset of points on a >>> >> heatmap? >> >>> I just would like see a particular set of genes standing out from the >>> >> rest. >> >>> Thank you, >>> Marek >>> >>> _______________________________________________ >>> Bioconductor mailing list >>> Bioconductor at stat.math.ethz.ch >>> https://stat.ethz.ch/mailman/listinfo/bioconductor >>> Search the archives: >>> >> http://news.gmane.org/gmane.science.biology.informatics.conductor >> >> _______________________________________________ >> Bioconductor mailing list >> Bioconductor at stat.math.ethz.ch >> https://stat.ethz.ch/mailman/listinfo/bioconductor >> Search the archives: >> http://news.gmane.org/gmane.science.biology.informatics.conductor >> >> > > [[alternative HTML version deleted]] > > _______________________________________________ > Bioconductor mailing list > Bioconductor at stat.math.ethz.ch > https://stat.ethz.ch/mailman/listinfo/bioconductor > Search the archives: http://news.gmane.org/gmane.science.biology.informatics.conductor >
ADD REPLY
0
Entering edit mode
You could try using densCols: my.colors <- c('red','blue','purple','orange') x =lapply(seq(2,10,by=2), function(j) rnorm(1000,j)) y =lapply(seq(2,10,by=2), function(k) rnorm(1000,k)) plot(1,1,xlim=c(0,10),ylim=c(0,10), pch='') lapply(1:4, function(i) points(x[[i]],y[[i]], col=densCols(x[[i]],y[[i]], col=colorRampPalette(c('white',my.colors[i]))), pch=3)) marek piatek (BI) wrote: > Hi Francois and all, > > Thanks for your advice. However if I will give my subset different values they will get clustered in different way - which is not what I want. Your approach is good if I wouldn't be using clustering. > And also the subset I would like to use different colour for is a subset of larger population (its min and max values are within the larger set). > > Any other ideas? > > Thank you in advance, > Marek > > > -----Original Message----- > From: Francois Pepin [mailto:francois at sus.mcgill.ca] > Sent: 18 June 2010 20:41 > To: marek piatek (BI) > Cc: bioconductor at stat.math.ethz.ch > Subject: Re: [BioC] different color for a subset of points on heatmap > > HI Marek, > > The easiest way I can think of: > > One would be give those genes a different set of values. So if all your data is between -5 to 5, have the special genes from say 10 to 20. Then you can send it a set of colors that covers everything. > > Here's an example where half is positive and half is negative. You can see the transparent colors in half of the columns as opposed to the non-transparent ones otherwise. > > >> heatmap(matrix(c(1,runif(49),-1,-runif(49)),10),col=cbind(heat.colo rs(20,alpha=0.25),heat.colors(20,alpha=1))) >> > > You'll need to be a bit careful to get the colors to match. I put the 1 and -1 to make sure that we cover the range and the colors and and values match. > > HTH, > > Francois > > On Jun 18, 2010, at 6:38 AM, marek piatek (BI) wrote: > > >> Hi all, >> >> Is there any way to use different color on a subset of points on a heatmap? >> I just would like see a particular set of genes standing out from the rest. >> >> Thank you, >> Marek >> >> _______________________________________________ >> Bioconductor mailing list >> Bioconductor at stat.math.ethz.ch >> https://stat.ethz.ch/mailman/listinfo/bioconductor >> Search the archives: http://news.gmane.org/gmane.science.biology.informatics.conductor >> > > _______________________________________________ > Bioconductor mailing list > Bioconductor at stat.math.ethz.ch > https://stat.ethz.ch/mailman/listinfo/bioconductor > Search the archives: http://news.gmane.org/gmane.science.biology.informatics.conductor >
ADD REPLY
0
Entering edit mode
I wouldn't necessarily change the colours (which mean something, scientifically). Not sure if anyone has mentioned it yet, but how about: library(gplots) library(geneplotter) mat <- matrix(rnorm(5000), ncol=10) heatmap.2(mat, key=FALSE, trace="none", col=greenred.colors(70), rowsep=c(50,100), sepcolor="yellow") ________________________________________ From: bioconductor-bounces@stat.math.ethz.ch [bioconductor- bounces@stat.math.ethz.ch] On Behalf Of David Schruth [dschruth@u.washington.edu] Sent: 21 June 2010 19:07 To: marek piatek (BI) Cc: bioconductor at stat.math.ethz.ch Subject: Re: [BioC] different color for a subset of points on heatmap You could try using densCols: my.colors <- c('red','blue','purple','orange') x =lapply(seq(2,10,by=2), function(j) rnorm(1000,j)) y =lapply(seq(2,10,by=2), function(k) rnorm(1000,k)) plot(1,1,xlim=c(0,10),ylim=c(0,10), pch='') lapply(1:4, function(i) points(x[[i]],y[[i]], col=densCols(x[[i]],y[[i]], col=colorRampPalette(c('white',my.colors[i]))), pch=3)) marek piatek (BI) wrote: > Hi Francois and all, > > Thanks for your advice. However if I will give my subset different values they will get clustered in different way - which is not what I want. Your approach is good if I wouldn't be using clustering. > And also the subset I would like to use different colour for is a subset of larger population (its min and max values are within the larger set). > > Any other ideas? > > Thank you in advance, > Marek > > > -----Original Message----- > From: Francois Pepin [mailto:francois at sus.mcgill.ca] > Sent: 18 June 2010 20:41 > To: marek piatek (BI) > Cc: bioconductor at stat.math.ethz.ch > Subject: Re: [BioC] different color for a subset of points on heatmap > > HI Marek, > > The easiest way I can think of: > > One would be give those genes a different set of values. So if all your data is between -5 to 5, have the special genes from say 10 to 20. Then you can send it a set of colors that covers everything. > > Here's an example where half is positive and half is negative. You can see the transparent colors in half of the columns as opposed to the non-transparent ones otherwise. > > >> heatmap(matrix(c(1,runif(49),-1,-runif(49)),10),col=cbind(heat.colo rs(20,alpha=0.25),heat.colors(20,alpha=1))) >> > > You'll need to be a bit careful to get the colors to match. I put the 1 and -1 to make sure that we cover the range and the colors and and values match. > > HTH, > > Francois > > On Jun 18, 2010, at 6:38 AM, marek piatek (BI) wrote: > > >> Hi all, >> >> Is there any way to use different color on a subset of points on a heatmap? >> I just would like see a particular set of genes standing out from the rest. >> >> Thank you, >> Marek >> >> _______________________________________________ >> Bioconductor mailing list >> Bioconductor at stat.math.ethz.ch >> https://stat.ethz.ch/mailman/listinfo/bioconductor >> Search the archives: http://news.gmane.org/gmane.science.biology.informatics.conductor >> > > _______________________________________________ > Bioconductor mailing list > Bioconductor at stat.math.ethz.ch > https://stat.ethz.ch/mailman/listinfo/bioconductor > Search the archives: http://news.gmane.org/gmane.science.biology.informatics.conductor > _______________________________________________ Bioconductor mailing list Bioconductor at stat.math.ethz.ch https://stat.ethz.ch/mailman/listinfo/bioconductor Search the archives: http://news.gmane.org/gmane.science.biology.informatics.conductor
ADD REPLY

Login before adding your answer.

Traffic: 689 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