0

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

我正在使用的代码如下:

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. angustidigitorum 岩石 绿色的 制服
E. antillensis 岩石 绿色的 制服
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", "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' 的片段是:

 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。

4

1 回答 1

0

我想我知道发生了什么。如果这不能解决您的问题,请告诉我,我们可以解决更多问题。你确定你用的是完整版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")

青蛙数据 2

于 2021-07-16T13:55:58.993 回答