【发布时间】:2013-08-02 11:12:28
【问题描述】:
您好,我正在使用 heatmap.2 在 R 中制作热图。我想使用 RowSideColors 选项。但是,我不知道如何轻松地为行创建颜色向量。
这些行代表细菌,我有一个数据框,其中包含我想用于着色的细菌信息。我将使用 Bact_Phylo_Info$Phylum 或 k 来创建颜色矢量。
> str(Bact_Phylo_Info)
'data.frame': 33 obs. of 3 variables:
$ Phylum: Factor w/ 7 levels "Actinobacteria",..: 4 3 3 2 2 2 2 2 5 5 ...
$ Order : Factor w/ 10 levels "Bacteroidales",..: NA 4 4 1 1 1 1 1 NA 5 ...
$ Family: Factor w/ 13 levels "Anaplasmataceae",..: NA 4 4 NA 11 2 11 12 NA NA ...
我已经尝试了一些东西,例如下面的疯狂循环,但我认为一定有一种我错过的简单方法。任何帮助表示赞赏。
BactPhyColors <- sapply(Bact_Phylo_Info$Phylum,
if (Bact_Phylo_Info$Phylum == levels(Bact_Phylo_Info$Phylum)[i]),
rainbow(length(levels(Bact_Phylo_Info$Phylum)))[i]
}
)
【问题讨论】: