由于scale_fill_manual错误,无法在系统发育树旁边绘制热图

时间:2019-06-16 08:31:45

标签: r ggtree

我正在尝试在系统树旁边绘制一个热图,并根据数据对热图进行着色。但是,当我尝试在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中的错误(值= heatmap.colours,中断= 1:7):找不到函数“ scale_fill_manual”

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

任何帮助将不胜感激!

0 个答案:

没有答案