【发布时间】:2015-05-14 09:08:38
【问题描述】:
:)
我有一个问题,通过个人搜索没有找到任何答案。 我想用分类变量制作一个热图(有点像这个:heatmap-like plot, but for categorical variables),我想在左侧添加一个系统发育树(像这个:how to create a heatmap with a fixed external hierarchical cluster)。理想的情况是改编第二个,因为它看起来更漂亮! ;)
这是我的数据:
-
一个newick格式的系统发育树,有3个物种,比方说:
((1,2),3); -
一个数据框:
x<-c("species 1","species 2","species 3") y<-c("A","A","C") z<-c("A","B","A") df<- data.frame(x,y,z)
(其中 A、B 和 C 是分类变量,例如在我的情况下存在/不存在/重复基因)。
你知道怎么做吗?
非常感谢!
编辑:我希望能够选择热图中每个类别的颜色,而不是经典的渐变。假设 A=绿色,B=黄色,C=红色
【问题讨论】:
-
你知道如何制作树状图吗?对于热图,您可以将分类值映射到数字并将其绘制为矩阵。
-
是的,我已经做了树状图!
mytree <-read.tree("sometree.tre") #turn the phylo tree to a dendrogram object data(mytree) #This is already a phylo object hc <- as.hclust(mytree) #Compulsory step as as.dendrogram doesn't have a method for phylo objects. dend <- as.dendrogram(hc) plot(dend, horiz=TRUE) -
但是如果我映射到数值,我可以为每个类别手动选择颜色吗?
-
当然,您可以选择自定义颜色(有很多关于如何做到这一点的选项)。
标签: r heatmap categorical-data phylogeny