Hello all,
I tried to generate a heatmap using heatmap.2
. The following code was used:
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:
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
myColors<- brewer.pal(8, "Set3")[1:length(unique(group))]
condn<- factor(c(rep("normal",3), rep("cancer",3)))
Where am I getting it wrong?
Regards,
Anthony
Hi Kevin,
Thank you for your response.
This is what is in
myColors
:For
group
I have this:condn
:The
group
andcondn
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 ingroup
andcondn
. How do I make this up?Am relatively new with R
Thank you,
Anthony
Can you try to re-format your post? - thanks!
Hello Kevin,
I hope the re-formatted post is ok. I am still learning learning how to write code on this platform.
Regards
You have 2 colours and 2 groups? If that is the case, then this should work
...or:
For
RowSideColors
, it is a different problem - I recommend that you avoid using that, for now.Hi Kevin,
I saw the error. It was from
sample_dist
I transposed the matrix like this:
The heatMap is ok now with both groups
Thanks
Hello Kelvin, pardon my formatting style. I am still learning it