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

此代码生成此图像:

enter image description here

更新的功能在这里:

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)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...