Search
Question: ColSideColors set by rows for heatmap.2 in RStudio
0
gravatar for austin.taylor
3 months 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?

ADD COMMENTlink modified 3 months ago by James W. MacDonald48k • written 3 months ago by austin.taylor0
2
gravatar for James W. MacDonald
3 months ago by
United States
James W. MacDonald48k 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.

ADD COMMENTlink written 3 months ago by James W. MacDonald48k

Thank you very much, it worked! I am new to R/RStudio and will take all of your comments into consideration. 

ADD REPLYlink written 3 months ago by austin.taylor0
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.2.0
Traffic: 160 users visited in the last hour