微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

使用 ggtree 时,“错误:必须从色调调色板中请求至少一种颜色”

如何解决使用 ggtree 时,“错误:必须从色调调色板中请求至少一种颜色”

我正在尝试创建一个系统发育树,为不同的背部模式显示不同颜色的尖端点,当我几周前第一次尝试时,它工作得很好,但现在尝试它我得到了上面的错误代码。自上次以来,我唯一做的不同是更新了一些软件包。

我使用的代码如下:

ggtree(frogtree.2,layout="circular") %<+% frogdata + geom_tiplab(offset = .3,hjust = .6) + theme(legend.position = "right") + geom_tippoint(aes(colour=PATTERN))

基于此错误的其他查询,我的数据中没有 NA,树加载良好,直到我使用 geom_tippoint(aes(fill = PATTERN))

由于此代码以前有效并且我没有更改数据的结构(字符和数字),我不确定问题出在哪里。

数据片段:

物种 微生境 颜色 模式
D.裂隙 WL 绿色 斑驳
E。指尖角 摇滚 绿色 制服
E。安特列斯 摇滚 绿色 制服
E。阿特金西 WL 棕色 对称
E。坎皮 地球 白色 制服
E。烹饪 摇滚 棕色 制服

提前致谢。

编辑: 使用 dput 我来自“frogdata”的数据片段是:

>dput(frogdata[1:10,1:4 ])
structure(list(SPECIES = c("D. diastema","E. angustidigitorum","E. antillensis","E. atkinsi","E. campi","E. cooki","E. coqui","E. cystignathoides","E. flavescens","E. grandis"),FAMILY = c("Eleutherodactylidae ","Eleutherodactylidae","Eleutherodactylidae"
),MICROHABITAT = c("WL","rock","WL","earth","WL"),COLOUR = c("green","green","brown","white","brown"
)),row.names = c(NA,10L),class = "data.frame")

来自“frogtree.2”的片段是:

 dput(frogtree.2)
structure(list(edge = structure(c(97L,97L,96L,95L,94L,93L,92L,91L,90L,89L,88L,87L,86L,85L,84L,83L,82L,81L,80L,79L,78L,77L,76L,75L,74L,73L,72L,71L,70L,69L,68L,67L,66L,65L,64L,63L,62L,61L,60L,59L,58L,57L,56L,55L,54L,53L,52L,51L,50L,48L,49L,47L,45L,46L,44L,41L,42L,43L,38L,39L,37L,34L,35L,36L,40L,32L,33L,31L,28L,29L,27L,24L,25L,23L,22L,21L,19L,20L,16L,17L,15L,13L,14L,12L,10L,11L,9L,7L,8L,5L,6L,3L,4L,18L,26L,30L,1L,2L,52L),.Dim = c(96L,2L)),edge.length = c(0.03940155,0.03940155,0.04827143,0.00886988,0.048902435,0.0147448041666667,0.0153758091666667,0.066352673,0.00270543383333331,0.02971821,0.00824750499999999,0.037965715,0.0608982058333334,0.0325112478333334,0.026269995,0.0532619825,0.0269919875,0.088415535,0.0125160194117647,0.100931554411765,0.0476695719117647,0.0364101436041083,0.0384777771825397,0.129893066666667,0.06590009,0.071875705,0.00597561499999999,0.037936535,0.0796354725,0.0416989375,0.0927819333333333,0.0131464608333333,0.1262746025,0.0334926691666667,0.054465585,0.03967896,0.058724815,0.019045855,0.0171324,0.05103453,0.03390213,0.03775446,0.0327989822727273,0.0195189122727273,0.0705534422727273,0.027401475,0.025252155,0.015455835,0.029841255,0.020044935,0.00717716249999999,0.0250727775,0.0369889491666667,0.0189097593939394,0.0464202691666667,0.0771586558333334,0.0416082706560284,0.177491741489362,0.123026156489362,0.0396052220062134,0.0908223609955752,0.217096963495575,0.0137432219084653,0.15896448040404,0.23084018540404,0.0170589140269943,0.118006032764368,0.110557401415162,0.27845723,0.239645341276596,0.270203471845561),Nnode = 48L,node.label = c("Root","1.0000","","0.1400","0.0980","0.2500","0.9920","0.5120","0.2720","0.3240","0.7240","0.9960","0.9840","0.7300","0.5600","0.9700","0.6420","0.7140","0.9080","0.7860","0.9980","0.9800","0.9540","0.8500","0.6300","0.8520","0.9020","0.9720","0.5000","0.1660","0.2740","0.3160","0.1840","0.0940","0.2180","0.4860","0.3740","0.9520","0.6320","0.7100","0.4920","0.5640","0.6080","0.5080","0.8960"),tip.label = c("Pl._thaul","En._petersi","E._angustidigitorum","E._grandis","E._modestus","E._pallidus","E._nitidus","E._pipilans","E._longipes","E._campi","E._cystignathoides","E._marnockii","E._guttilatus","E._verrucipes","E._atkinsi","E._planirostris","E._rogersi","E._inoptatus","E._johnstonei","E._martinicensis","E._flavescens","E._antillensis","E._cooki","E._coqui","E._portoricensis","D._diastema","Pl._bufoninum","Pl._cinereum","Pl._brachyops","Le._fragilis","En._pustulosus","Ph._cuvieri","Ps._falcipes","Ad._andreae","Li._lineatus","Le._wagneri","Le._melanonotus","Le._latrans","Le._macrosternum","Le._insularum","Le._pentadactylus","Le._savagei","Le._knudseni","Le._latinasus","Le._albilabris","Le._mystacinus","Le._fuscus","Le._gracilis","Le._mystaceus")),class = "phylo",order = "postorder",RSS = 12.8678101120044)

这棵树是通过

作为newick文件导入的
read.tree("frog.tree.nwk")

我尝试使用的软件包是:

library(tidyverse)
library(ape)
library(caper)
library(geiger)
library(maps)
library(phytools)
library(picante)
library(stringr)
library(adegenet)
library(stats)
library(ips)
library(phylobase)
library(ade4)
library(caper)
library(geiger)
library(phytools)
library(vegan)
library(lattice)
library(nlme)
library(MASS)
library(scales)
library(treeplyr)
library(phangorn)

更新: 所以我使用@Skaqqs 提供的代码

```dat.1 <- data.frame(SPECIES = frogtree.2$tip.label,PATTERN = sample(frogdata$PATTERN,size = length(frogtree.2$tip.label),replace = T))```

这适用于 ggtree 代码

```ggtree(frogtree.2,layout="circular",branch.length = "none") %<+% dat.1 + geom_tiplab(offset = 7,hjust = .6) + geom_tippoint(aes(colour = PATTERN),cex = 4) + theme(legend.position = "right")```

但是 dat.1 DF 与我的数据集不一致,因此它生成的树无效。 我还想看看是否可以使用我的数据集(整个 DF 的完整 dput 输出)将 REGION 作为形状美学添加到树中:

```structure(list(SPECIES = structure(c(2L,.Label = c("Ad. Andreae","D.diastema","E. grandis","E. guttilatus","E. inoptatus","E. johnstonei","E. leprus","E. longipes","E. marnockii","E. martinicensis","E. modestus","E. nitidus","E. pallidus","E. pipilans","E. planirostris","E. portoricensis","E. rogersi","E. verrucipes","E.angustidigitorum","En. petersi","En. pustulosus","Le. albilabris","Le. fragilis","Le. fuscus","Le. iatrans","Le. insularum","Le. knudseni","Le. latinasus","Le. macrosternum","Le. melanonotus","Le. mystaceus ","Le. mystacinus","Le. pentadactylus","Le. savagei","Le. wagneri","Le.gracilis","Li. lineatus","Ph. cuvieri","Pl. brachyops","Pl. bufoninum","Pl. cinereum","Pl. thaul","Ps. falcipes"),class = "factor"),"Eleutherodactylidae"),MICROHABITAT = structure(c(7L,7L),.Label = c("earth","grass","LL","stones","surface",COLOUR = structure(c(3L,2L),.Label = c("beige","grey","orange","white"),PATTERN = structure(c(3L,3L),.Label = c("Barred","Complex","Mottled","Symmetrical","Uniform"),COLOUR.1 = structure(c(7L,9L),"black","peach","red","rufous","yellow"),TONE = c(55.5,56.3,30.5,31.9,38.6,33.9,58.3,45,55.7,58.7),disTANCE = c(1187.23,2185.09,2024.26,2285.65,3172.5,2039.48,2216.22,2264.15,2113.5,2147.5),REGION = structure(c(2L,.Label = c("Caribbean","Central America","north America","northern South America","Southern South America"),class = "factor")),class = "data.frame")```

然后我从我的数据集中创建了另一个 DF:

```dat <- data.frame(SPECIES = frogdata$SPECIES,PATTERN = frogdata$PATTERN,REGION=frogdata$REGION)```

绘制它:

```ggtree(frogtree.2,branch.length = "none") %<+% dat + geom_tiplab(offset = 7,hjust = .6) + geom_tippoint(aes(colour = PATTERN,shape=REGION),cex = 4) + theme(legend.position = "right")```

但我收到此警告消息: 警告信息:

```Removed 6 rows containing missing values (geom_point_g_gtree).```

还有这个数字:

https://i.stack.imgur.com/JxdCq.png

我看不出我的数据集有什么问题来获取此警告代码和缺少的提示点,我看不到任何 NA。

解决方法

我想我知道发生了什么。如果这不能解决您这边的问题,请告诉我,我们可以解决更多问题。您确定您使用的是完整版的 frogdata 吗?如果 frogdata 中的物种少于 frogtree.2,我会收到错误消息:

library(ggtree)

# frogtree.2 <- data.frame(...)

frogdata <- data.frame(
  SPECIES = c("D. diastema","E. angustidigitorum","E. antillensis","E. atkinsi","E. campi","E. cooki","E. coqui","E. cystignathoides","E. flavescens","E. grandis"),FAMILY = c("Eleutherodactylidae ","Eleutherodactylidae","Eleutherodactylidae"),MICROHABITAT = c("WL","rock","WL","earth","WL"),COLOUR = c("green","green","brown","white","brown"))

# Add pattern field
frogdata$PATTERN <- c("Mottled","Uniform","Symmetrical","Blank","Blank")

# Plot fails
ggtree(frogtree.2,layout="circular") %<+%
  frogdata +
  geom_tiplab(offset = .3,hjust = .6) +
  geom_tippoint(aes(colour = PATTERN)) +
  theme(legend.position = "right")
#> Error: Must request at least one colour from a hue palette.

但是当我使用树中的所有物种创建示例数据集时:

# Create new frogdata with same number of species as frogtree.2
dat <- data.frame(
  SPECIES = frogtree.2$tip.label,PATTERN = sample(frogdata$PATTERN,size = length(frogtree.2$tip.label),replace = TRUE))

# New plot
ggtree(frogtree.2,layout="circular") %<+%
  dat +
  geom_tiplab(offset = .3,hjust = .6) +
  geom_tippoint(aes(colour = PATTERN)) +
  theme(legend.position = "right")

frogdata 2

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?