如何解决gheatmap函数ggtree程序包返回“错误:必须从色调调色板请求至少一种颜色”绘制gheatmap对象时
我正在尝试使用ggtree函数gheatmap将热图添加到系统树上。尽管创建gheatmap对象的行中没有出现明显的错误,但是在尝试绘制该对象时,它会返回“错误:必须从色调调色板中请求至少一种颜色。”。当我将所有默认值用作gheatmap的参数(包括颜色选择),更简单的树以及一些与树的技巧相对应的随机值时,仍然会收到此错误。我还尝试过更改某些颜色,但仍然无法解决错误,因为我仍不确定是哪个参数导致了问题。
我希望这是一个可复制的示例:
library(ggtree)
test.tree <- read.tree(text = "(((A,C),(B,D)),E);")
test.data <- data.frame('taxon' = c('A','B','C','D','E'),'height' = c(0.7,0.2,1.3,0.55,0.88))
test.tree.plot <- ggtree(test.tree)
test.plot <- gheatmap(
test.tree.plot,test.data,offset = 0,width = 1,low = "green",high = "red",color = "white",colnames = TRUE,colnames_position = "bottom",colnames_angle = 0,colnames_level = NULL,colnames_offset_x = 0,colnames_offset_y = 0,font.size = 4,family = "",hjust = 0.5,legend_title = "value"
)
plot(test.plot)
解决方法
欢迎来到!
对此错误的快速搜索指向将仅包含NA
的变量映射到美观对象的情况(在这种情况下为fill
的{{1}})。您的数据没有任何geom_tile()
,因此它可能在NA
函数内部发生了某些事情。
仔细观察一下,在https://github.com/YuLab-SMU/ggtree/blob/232394961afb6ce62c8dd90a5b1ee8e5f557185a/R/gheatmap.R#L81这行上,gheatmap
函数期望数据帧具有gheatmap
。除非您遇到这种情况,否则数据中没有行名,而行名经过rownames
向下移动几步后就没有所有NA
的行名。
我将函数更新为采用另一个参数gather
,该参数将列设置为用于行名。
使用新功能,代码将为:
id_col
此代码生成此图像:
更新的功能在这里:
library(ggtree)
library(magrittr)
library(dplyr)
library(tidyr)
library(ggplot2)
source("ggheatmap.R") # loading the new function (if in a separate file)
test.tree <- read.tree(text = "(((A,C),(B,D)),E);")
test.data <- data.frame('taxon' = c('A','B','C','D','E'),'height' = c(0.7,0.2,1.3,0.55,0.88)
)
test.tree.plot <- ggtree(test.tree)
test.plot <- ggheat(
test.tree.plot,test.data,id_col = "taxon",# here is where you set the column with species names
# this becomes rownames internaly
# and is matched to the tip names
offset = -3,width = 1,low = "green",high = "red",color = "white",colnames = TRUE,colnames_position = "bottom",colnames_angle = 0,colnames_level = NULL,colnames_offset_x = 0,colnames_offset_y = 0,font.size = 4,family = "",hjust = 0.5,legend_title = "value"
)
plot(test.plot)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。