0

我正在尝试在系统发育树旁边绘制热图并根据数据为热图着色。但是,当我尝试在 R 中使用 ggtree 进行绘制时,出现错误:找不到函数“scale_fill_manual”。

我尝试了几次网络搜索来解决这个问题。我的代码基于以前发布的示例:https ://github.com/GuangchuangYu/plotTree-ggtree/blob/master/03_curated_genes.R

这是系统发育数据的示例(newick 格式的树文件):

(B:6.0,(A:5.0,C:3.0,E:4.0):5.0,D:11.0);

这是热图数据(csv 格式文件)的示例:

Genome Data_1 Data_2
A      1      5
B      2      5
C      2      6
D      3      7
E      4      7

这是我当前的 R 脚本:

library(ggtree)
library(ape)
library(phytools) #needed for midpoint rooting

#read in tree
t<-read.tree("RAxML_bestTree.BestTree")
#midpoint root tree
rooted <- midpoint.root(t)
#ladderise midpoint rooted tree (F is false --> ascending, T is true --> descending)
tl_f <- ladderize(rooted, F)

#read in the metadata
tipcategories = read.csv("metadata.csv", 
                         sep = "\t",
                         row.names=1,
                         header = TRUE, 
                         stringsAsFactors = FALSE)
rn <- rownames(tipcategories)
heatmapData <- as.data.frame(sapply(tipcategories, as.character))
rownames(heatmapData) <- rn
head(heatmapData)

#setup colour range, need 7 different colours
heatmap.colours=c("green","red","orange","pink","purple","blue","gold")
names(heatmap.colours) <- 1:7

#plot tree
p <- ggtree(tl_f) + geom_tiplab(size=1, color="purple")
p2 <- gheatmap(p, heatmapData, offset = 2, color=NULL, colnames_position="top", 
colnames_angle=90, colnames_offset_y = 1, hjust=0, font.size=2) + 
scale_fill_manual(values=heatmap.colours,breaks=1:7)
p2

我希望这个网站上的情节类似于情节 3:https ://github.com/GuangchuangYu/plotTree-ggtree ,但是我收到错误:scale_fill_manual 中的错误(values = heatmap.colours,breaks = 1:7):可以找不到功能“scale_fill_manual”

我正在使用 R 版本 3.6.0、Bioconductor 版本 3.9 (BiocManager 1.30.4) 和 ggtree 版本 1.16.1

任何帮助将不胜感激!

4

0 回答 0