Question: ColSideColors' must be a character vector of length ncol(x)
1
gravatar for anthonyimhez
6 weeks ago by
anthonyimhez20
anthonyimhez20 wrote:

Hello all, I tried to generate a heatmap using heatmap.2 The following code was used:

<code>heatmap.2(as.matrix(sample_dist), key=F, trace="none",Colv = c("cancer", "normal"),Rowv ="Colv",dendrogram= "none",col=colorpanel(100, "black", "white"),ColSideColors=myColors[condn], RowSideColors=myColors[condn],margin=c(10, 10), main="Sample Distance Matrix")

Then, I got this error:

<code>Error in heatmap.2(as.matrix(sample_dist), key = F, trace = "none", Colv = c("cancer", : 'ColSideColors' must be a character vector of length ncol(x)

Does this mean that "myColors" is not same as "condn"?

This was how i defined myColors and "condn"

<code>myColors<- brewer.pal(8, "Set3")[1:length(unique(group))]
<code>condn<- factor(c(rep("normal",3), rep("cancer",3)))

where, am I getting it wrong?

Regards, Anthony

ADD COMMENTlink modified 6 weeks ago • written 6 weeks ago by anthonyimhez20

Hello Kelvin, pardon my formatting style. I am still learning it

ADD REPLYlink written 6 weeks ago by anthonyimhez20
1
gravatar for Kevin Blighe
6 weeks ago by
Kevin Blighe71k
Republic of Ireland
Kevin Blighe71k wrote:

It is likely that, when you solve this first error, a subsequent error will appear relating to RowSideColors.

The only thing that you need to pass to ColSideColors and RowSideColors are character vectors of colours that have the same length as ncol(x) and nrow(x), respectively.

  • What, currently, is contained in myColours?
  • What is group?
  • What are you aiming to do with this: myColors[condn]?

At the very fundamental level, we can assign a pre-defined colour palette like this:

samples <- c('Primary','Primary','Normal','Met','Normal','Normal','Met','Met','Primary','Normal')
samples <- factor(samples, levels = c('Normal', 'Primary', 'Met'))
RColorBrewer::brewer.pal(11, 'Spectral')[samples]
 [1] "#D53E4F" "#D53E4F" "#9E0142" "#F46D43" "#9E0142" "#9E0142" "#F46D43" "#F46D43" "#D53E4F" "#9E0142"

Other ways to assign colours to factors:

colorRampPalette(c('pink', 'purple', 'red4'))(length(unique(samples)))[samples]
 [1] "#A020F0" "#A020F0" "#FFC0CB" "#8B0000" "#FFC0CB" "#FFC0CB" "#8B0000" "#8B0000" "#A020F0"
[10] "#FFC0CB"

...or even just:

c('pink', 'purple', 'red4')[samples]
 [1] "purple" "purple" "pink"   "red4"   "pink"   "pink"   "red4"   "red4"   "purple" "pink"

Gracias!

Kevin

ADD COMMENTlink modified 6 weeks ago • written 6 weeks ago by Kevin Blighe71k

Hi Kelvin, Thank you for your response.

This is what is in myColors: [1] "#8DD3C7" "#FFFFB3"

 for 'group'  I have this:

factor w/2 levels "HBR; "UHR" : 1 1 1 2 2 2>`

condn

factor w/2 levels "cancer", "normal" : 2 2 2 1 1 1

The 'group' and 'condn' are what am using for my comparison in my Differential gene Expression.

from your examples, I think I have few numbers of colors compare to what i have in "group" and "condn".

How do I make this up?

Am relatively new with R

Thank you,
Anthony
ADD REPLYlink modified 6 weeks ago • written 6 weeks ago by anthonyimhez20

Can you try to re-format your post? - thanks!

ADD REPLYlink written 6 weeks ago by Kevin Blighe71k

Hello Kelvin,

I hope the re-formatted post is ok. am still learning learning how to write codes in this Platform.

Regards

ADD REPLYlink written 6 weeks ago by anthonyimhez20

You have 2 colours and 2 groups? If that is the case, then this should work

myColors[condn]

...or:

myColors[group]

For RowSideColors, it is a different problem - I recommend that you avoid using that, for now.

ADD REPLYlink modified 6 weeks ago • written 6 weeks ago by Kevin Blighe71k
1

Hi Kelvin, I saw the error. It was from sample_dist

I tranposed the matrix like this:

 <code>sample_dist<- as.matrix(dist(t(assay(rlog_Trans))))

The heatMap is ok now with both groups

Thanks

ADD REPLYlink modified 6 weeks ago • written 6 weeks ago by anthonyimhez20
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.3.0
Traffic: 1021 users visited in the last hour
_