【问题标题】:'Error: Must request at least one colour from a hue palette' when using ggtree使用 ggtree 时,“错误:必须从色调调色板中请求至少一种颜色”
【发布时间】:2021-09-16 12:16:30
【问题描述】:

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

我使用的代码如下:

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))

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

数据sn-p:

SPECIES MICROHABITAT COLOUR PATTERN
D. diastema WL Green Mottled
E. angustidigitorum Rock Green Uniform
E. antillensis Rock Green Uniform
E. atkinsi WL Brown Symmetrical
E. Campi Earth White Uniform
E. cooki Rock Brown Uniform

提前致谢。

编辑: 从使用 dput 我的数据 sn-p 来自 '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", "Eleutherodactylidae", 
"Eleutherodactylidae", "Eleutherodactylidae", "Eleutherodactylidae", 
"Eleutherodactylidae", "Eleutherodactylidae", "Eleutherodactylidae"
), MICROHABITAT = c("WL", "rock", "rock", "WL", "earth", "earth", 
"rock", "WL", "WL", "WL"), COLOUR = c("green", "green", "green", 
"brown", "white", "brown", "brown", "green", "green", "brown"
)), row.names = c(NA, 10L), class = "data.frame")

'frogtree.2' 的 sn-p 是:

 dput(frogtree.2)
structure(list(edge = structure(c(97L, 97L, 96L, 96L, 95L, 95L, 
94L, 94L, 93L, 93L, 92L, 92L, 91L, 91L, 90L, 90L, 89L, 89L, 88L, 
88L, 87L, 87L, 86L, 86L, 85L, 85L, 84L, 84L, 83L, 83L, 82L, 82L, 
81L, 81L, 80L, 80L, 79L, 79L, 78L, 78L, 77L, 77L, 76L, 76L, 75L, 
75L, 74L, 74L, 73L, 73L, 72L, 72L, 71L, 71L, 70L, 70L, 69L, 69L, 
68L, 68L, 67L, 67L, 66L, 66L, 65L, 65L, 64L, 64L, 63L, 63L, 62L, 
62L, 61L, 61L, 60L, 60L, 59L, 59L, 58L, 58L, 57L, 57L, 56L, 56L, 
55L, 55L, 54L, 54L, 53L, 53L, 52L, 52L, 51L, 51L, 50L, 50L, 48L, 
49L, 47L, 97L, 45L, 46L, 95L, 96L, 44L, 94L, 41L, 42L, 92L, 43L, 
91L, 93L, 38L, 39L, 37L, 89L, 34L, 35L, 87L, 36L, 86L, 88L, 85L, 
40L, 84L, 90L, 32L, 33L, 31L, 82L, 28L, 29L, 27L, 80L, 24L, 25L, 
23L, 78L, 22L, 77L, 21L, 76L, 19L, 20L, 16L, 17L, 15L, 73L, 13L, 
14L, 12L, 71L, 10L, 11L, 69L, 70L, 9L, 68L, 7L, 8L, 5L, 6L, 3L, 
4L, 64L, 65L, 63L, 66L, 62L, 67L, 61L, 72L, 60L, 18L, 59L, 74L, 
58L, 75L, 57L, 26L, 56L, 79L, 55L, 30L, 54L, 81L, 53L, 83L, 1L, 
2L, 51L, 52L), .Dim = c(96L, 2L)), edge.length = c(0.03940155, 
0.03940155, 0.04827143, 0.00886988, 0.048902435, 0.048902435, 
0.0147448041666667, 0.0153758091666667, 0.066352673, 0.00270543383333331, 
0.02971821, 0.02971821, 0.00824750499999999, 0.037965715, 0.0608982058333334, 
0.0325112478333334, 0.026269995, 0.026269995, 0.0532619825, 0.0269919875, 
0.088415535, 0.088415535, 0.0125160194117647, 0.100931554411765, 
0, 0.0476695719117647, 0, 0.100931554411765, 0.0364101436041083, 
0.0384777771825397, 0.129893066666667, 0.129893066666667, 0.129893066666667, 
0, 0.06590009, 0.06590009, 0.071875705, 0.00597561499999999, 
0.037936535, 0.037936535, 0.0796354725, 0.0416989375, 0.0927819333333333, 
0.0131464608333333, 0.1262746025, 0.0334926691666667, 0.054465585, 
0.054465585, 0.03967896, 0.03967896, 0.058724815, 0.019045855, 
0.0171324, 0.0171324, 0.05103453, 0.03390213, 0.03775446, 0.03775446, 
0.0327989822727273, 0.0195189122727273, 0.0705534422727273, 0, 
0.027401475, 0.027401475, 0.025252155, 0.025252155, 0.015455835, 
0.015455835, 0.029841255, 0.020044935, 0.00717716249999999, 0.0250727775, 
0.0369889491666667, 0.0189097593939394, 0.0464202691666667, 0.0771586558333334, 
0.0416082706560284, 0.177491741489362, 0, 0.123026156489362, 
0.0396052220062134, 0.0908223609955752, 0, 0.217096963495575, 
0.0137432219084653, 0.15896448040404, 0, 0.23084018540404, 0.0170589140269943, 
0.118006032764368, 0, 0.110557401415162, 0.27845723, 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", 
"1.0000", "0.9700", "0.6420", "0.7140", "0.9080", "0.7860", "0.9980", 
"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", "1.0000", "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, 26L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L), .Label = c("Ad. Andreae", "D.diastema", "E. antillensis", "E. atkinsi", "E. campi", "E. cooki", "E. coqui", "E. cystignathoides","E. flavescens", "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"), FAMILY = c("Eleutherodactylidae ", "Eleutherodactylidae", "Eleutherodactylidae", "Eleutherodactylidae", "Eleutherodactylidae", "Eleutherodactylidae", "Eleutherodactylidae", "Eleutherodactylidae", "Eleutherodactylidae", "Eleutherodactylidae"), MICROHABITAT = structure(c(7L, 4L, 4L, 7L, 1L, 1L, 4L, 7L, 7L, 7L), .Label = c("earth", "grass", "LL", "rock", "stones", "surface", "WL"), class = "factor"), COLOUR = structure(c(3L, 3L, 3L, 2L, 6L, 2L, 2L, 3L, 3L, 2L), .Label = c("beige", "brown", "green", "grey", "orange", "white"), class = "factor"), PATTERN = structure(c(3L, 5L, 5L, 4L, 5L, 5L, 4L, 3L, 2L, 3L), .Label = c("Barred", "Complex", "Mottled", "Symmetrical", "Uniform"), class = "factor"), COLOUR.1 = structure(c(7L, 3L, 6L, 3L, 4L, 3L, 1L, 1L, 10L, 9L), .Label = c("beige", "black", "brown", "green", "grey", "orange", "peach", "red", "rufous", "yellow"), class = "factor"), 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, 3L, 1L, 1L, 3L, 1L, 3L, 3L, 1L, 3L), .Label = c("Caribbean", "Central America", "North America", "Northern South America", "Southern South America"), class = "factor")), row.names = c(NA, 10L), class = "data.frame")```

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

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

绘制它:

```ggtree(frogtree.2, layout="circular", 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。

【问题讨论】:

  • 您可以共享 MRE 吗? stackoverflow.com/questions/5963269/…
  • 您还需要问题中未提供的哪些其他信息?很抱歉我很久没有使用 R。
  • 一个 MRE 包含重现您面临的问题所需的所有代码和数据。我看到你提供了一个示例数据集,谢谢!但是,以 R 友好的方式共享数据(例如使用 dput();参见上面链接中的示例)通常会得到更多答案。考虑这一点的一种好方法是打开一个新脚本并输入您在问题中提供的所有信息;这足以看出问题了吗?你分享的数据sn-p是frogtree.2的例子吗?需要什么包?我期待着尝试帮助回答您的问题。谢谢!
  • 您好,非常感谢您的帮助!我已经以代码形式添加了我的数据和树 sn-ps,我希望这是您所需要的!我还添加了之前尝试加载的包,我猜主要是 tidyverse、ggtree、ggplot2
  • 你能分享dput(frogtree.2)的结果吗?我无法用frogdata 制作树。

标签: r ggplot2 phylogeny ggtree


【解决方案1】:

我想我知道发生了什么。如果这不能解决您的问题,请告诉我,我们可以解决更多问题。你确定你使用的是完整版的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", "Eleutherodactylidae", "Eleutherodactylidae", "Eleutherodactylidae", "Eleutherodactylidae", "Eleutherodactylidae", "Eleutherodactylidae", "Eleutherodactylidae"),
  MICROHABITAT = c("WL", "rock", "rock", "WL", "earth", "earth", "rock", "WL", "WL", "WL"),
  COLOUR = c("green", "green", "green", "brown", "white", "brown", "brown", "green", "green", "brown"))

# Add pattern field
frogdata$PATTERN <- c("Mottled", "Uniform", "Uniform", "Symmetrical", "Uniform", "Uniform", "Blank", "Blank", "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")

【讨论】:

  • 嘿,很抱歉延迟回复。我发现树上少了一个物种,我纠正了。但是,这个代码成功了一半,所以它生成了一棵与此处显示的树相似的树,但物种与正确的身体模式不匹配。有没有办法使用原始数据集来确保列出物种的正确体型?我在尝试使用原始数据集和修正树时遇到另一个问题,我收到一条警告消息:Removed 6 rows containing missing values (geom_point_g_gtree)我在使用上述代码时没有收到此错误
  • 如果你能用你当前的工作代码和你看到的任何问题来更新你的原始问题,那就太好了!在那之后,我很乐意尝试弄清楚发生了什么。
  • 嘿 Skaqqs,我已经更新了问题!我希望它很清楚。
  • 我在问题中看到了您的更新,谢谢! frogtree.2 在您的新代码中是如何定义的?简单来说,您收到的新警告表明 frogtree.2dat 中的物种不匹配。也就是说,如果物种 A 没有在树上标记,ggtree 不知道如何绘制代表物种 A 的点。您可以使用setdiff(dat$SPECIES, frogtree.2$tip.label) 之类的内容开始诊断。顺便说一句很酷的情节!
  • 经过漫长而乏味的旅程,这一切都归结为我的 DF 和树之间的几个相反的大写字母和空格。我终于满意了,非常感谢您的帮助!可能早就放弃了。 :)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-12-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-03-10
  • 2020-03-31
相关资源
最近更新 更多