Search
Question: ColSideColors set by rows for heatmap.2 in RStudio
0
5 weeks ago by
austin.taylor0 wrote:

I can't figure out to make a condition_colors for ColSideColors with Heatmap.2 in RStudio.

I have a matrix in csv file with 49 genes as rows and 11 samples, I want to group the genes by biological process. The first 8 genes I want one color, the next 10 genes another, an so forth like below.

# Set column side colors
condition_colors <- unlist(lapply(row.names(Data),function(x){
if(grepl([1:8,],x)) '#FF0000'
else if(grepl([9:19,]),x)) '#FF7F7F'
else if(grepl([20:27,],x)) '#0000FF'
else if (grepl([28:49,],x)) '#8080FF'
}))

This does not work, how does one continue?

modified 5 weeks ago by James W. MacDonald47k • written 5 weeks ago by austin.taylor0
2
5 weeks ago by
United States
James W. MacDonald47k wrote:

This function comes from gplots, a CRAN package, so you should be asking this question on R-help (r-help@r-project.org). That said, from ?heatmap.2, there is this:

ColSideColors: (optional) character vector of length 'ncol(x)'
containing the color names for a horizontal side bar that may
be used to annotate the columns of 'x'.

RowSideColors: (optional) character vector of length 'nrow(x)'
containing the color names for a vertical side bar that may
be used to annotate the rows of 'x'.

Using ColSideColors to annotate your genes (which are in rows) seems not the way to proceed.

In addition that if/else stack is sort of the hard way to do things. Wouldn't

condition_colors <- rep(c('#FF0000','#FF7F7F','#0000FF','#8080FF'), c(8,11,8,22))

be a simpler way to do that? Also note that 9:19 has 11 items, not 10, so your counting might be off as well.