R 在系统发育图上绘制特征

R 在系统发育图上绘制特征,r,plot,data-visualization,phylogeny,ape-phylo,R,Plot,Data Visualization,Phylogeny,Ape Phylo,下面我将介绍如何在系统发育图上绘制特征,以确定特征保守性。我一步一步地遵循它,但似乎无法让社区组成或系统发育特征图对我的数据集起作用。正如他们所说,我已经格式化了,看起来就像他们的示例数据发送给我一样 我不知道如何把树文件放在这里,所以这里有一个云链接,这是一棵树,我只是用来绘制特征 VegComm <- df2vec(as.matrix(Veg2018), colID = 1:29) #community data STraits <- read.csv() rownames

下面我将介绍如何在系统发育图上绘制特征,以确定特征保守性。我一步一步地遵循它,但似乎无法让社区组成或系统发育特征图对我的数据集起作用。正如他们所说,我已经格式化了,看起来就像他们的示例数据发送给我一样

我不知道如何把树文件放在这里,所以这里有一个云链接,这是一棵树,我只是用来绘制特征

VegComm <- df2vec(as.matrix(Veg2018), colID = 1:29)  #community data


STraits <- read.csv()
rownames(STraits)<- STraits[,1]
STraits[1:1] <- list(NULL)    #Trait Data



STraits <- df2vec(as.matrix.data.frame(STraits), colID=1:5)

STraits <- STraits[1:6,]
str(STraits)

prune.sample(VegComm,alltree)

par(mfrow=c(2,2))
for (i in colnames(STraits)) {
+ plot(nativetree, show.tip.label=TRUE, main=i)
+ tiplabels(pch=22, col=STraits[,i]+1, bg=STraits[,i]+1, cex=1.5)}

traits <- STraits[nativetree$tip.label,]

phylosignal(nativetree, STraits, nsim=1000, method="K")
以下是特征数据:(我试着省略和不省略NAs)

以下是
dput
输出:

> dput(STraits)
structure(c(0.035049437, 0.029380702, 0.00652489, 0.01441308, 
0.020075948, 0.01546666, 14.56355219, 1.245833333, 0.00652489, 
5.477777778, 4.974358974, 5.28968254, 11.78670881, 1.076820745, 
0.011364841, 5.117901992, 4.901863202, 6.055307558, 180.1322546, 
262.1630059, 3.412857143, 181.6818246, 142.4036892, 122.3827137, 
99.50427931, 60.49033956, 2.976064883, 42.91299583, 39.11274955, 
32.67582669), .Dim = c(6L, 5L), .Dimnames = list(c("Artemisia_californica", 
"Eschscholzia_californica", "Mimulus_aurantiacus", "Sisyrinchium_bellum", 
"Sidalcea_malviflora", "Stipa_pulchra"), c("Growth_Rate", "Area", 
"AreaVar", "SLA", "SLAVar")))

> dput(VegComm)
structure(list(Avena_fatua = c(0, 0.5, 0.333333333, 0.333333333, 
1.916666667, 0.333333333, 2.25, 2.5, 2.25, 4.75, 4.75, 2.5, 1.583333333, 
0, 2.25), Bromus_diandrus = c(1.25, 0, 4.083333333, 1.25, 0, 
3, 4, 0, 0, 0, 1.75, 0, 1.25, 1.25, 2.083333333), Bromus_hordeaceus = c(0, 
0.333333333, 0, 3.333333333, 8.833333333, 0, 0, 0, 1.5, 1.75, 
0.666666667, 4, 0, 6.666666667, 0.333333333), Festuca_myuros = c(20.83333333, 
14.16666667, 27.5, 10.41666667, 10.91666667, 6.25, 6.5, 5.083333333, 
2.5, 7, 11.83333333, 21.66666667, 10.66666667, 9.916666667, 10.41666667
), Festuca_perennis = c(7.416666667, 2.25, 3.333333333, 15.83333333, 
6.666666667, 2.25, 1.25, 1.25, 1.75, 2.083333333, 4.916666667, 
4.666666667, 4.25, 8.25, 4.416666667), Carduus_pycnocephalus = c(0.5, 
0, 6.083333333, 5.833333333, 0, 16, 13.75, 0.833333333, 0, 4.666666667, 
0, 0.5, 5.75, 0, 1.25), Cirsium_vulgare = c(0, 0, 0, 0, 0.333333333, 
0, 0, 0, 2.5, 0, 0, 0, 0, 0, 0), Erodium_cicutarium = c(0, 0, 
0, 0, 0, 0, 4.166666667, 5.916666667, 0, 0, 0, 0, 0, 0, 0), Geranium_dissectum = c(21.25, 
25, 15.83333333, 25.83333333, 15, 11.41666667, 10.5, 20.83333333, 
22.91666667, 18.08333333, 15, 25.41666667, 12.5, 33.33333333, 
23.33333333), Helminthotheca_echioides = c(0.333333333, 0, 1.75, 
0, 1.25, 0.333333333, 0, 0, 0, 0, 2.833333333, 0, 0, 0, 0), Lactuca_serriola = c(0, 
1.916666667, 2.416666667, 1.583333333, 1.75, 0, 0, 0, 0, 0, 1.25, 
1.25, 1.5, 0, 0), Medicago_polymorpha = c(6.916666667, 30.41666667, 
3.833333333, 10.75, 0, 3.833333333, 6.666666667, 16.66666667, 
19.16666667, 4.25, 39.16666667, 7.083333333, 30, 5.833333333, 
4.583333333), Oxalis_pes.caprae = c(0, 0, 0, 0, 0, 0, 0, 0, 2.916666667, 
0, 0, 0, 0, 0, 0), Raphanus_sativus = c(4.916666667, 3.666666667, 
6.666666667, 5.833333333, 3.333333333, 0.833333333, 4.5, 7.583333333, 
18.33333333, 13.75, 0.666666667, 14.58333333, 0.333333333, 5.833333333, 
5.083333333), Senecio_vulgaris = c(0, 0.833333333, 0, 0, 0, 0, 
0, 0, 0, 0, 0, 0, 0, 0, 0), Sonchus_oleraceus = c(0, 0.833333333, 
5.916666667, 1.25, 10.83333333, 1.166666667, 0, 1.333333333, 
0, 0, 3.833333333, 0.833333333, 0.333333333, 2.083333333, 0), 
    Vicia_sativa = c(0, 0, 0, 0, 0.5, 0, 0, 0, 0, 0, 0, 0, 0, 
    0, 13.33333333), Artemisia_californica = c(4.583333333, 0, 
    1.25, 0, 0, 0, 1.583333333, 0, 2.916666667, 0, 0, 1.25, 3.833333333, 
    0, 12.66666667), Baccharis_pilularis = c(18.33333333, 17.91666667, 
    2.083333333, 2.083333333, 3.333333333, 12, 3.833333333, 4.5, 
    6.666666667, 0, 4.166666667, 1.25, 0, 1.25, 8.333333333), 
    Ericameria_ericoides = c(1.25, 0, 0, 0, 0.5, 0, 0, 0, 0, 
    0, 0, 0, 0, 0, 0), Mimulus_aurantiacus = c(0.833333333, 0, 
    2.5, 0, 0, 0.166666667, 4.166666667, 0, 1.25, 0, 0, 0, 0, 
    0, 0), Bromus_carinatus = c(0.5, 2.083333333, 5.416666667, 
    0, 4.666666667, 3.333333333, 4.166666667, 0.333333333, 5.5, 
    0, 0.833333333, 3.333333333, 2.083333333, 2.5, 0), Elymus_triticoides = c(0L, 
    0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L), 
    Hordeum_brachyantherum = c(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 
    0L, 0L, 0L, 0L, 0L, 0L, 0L), Stipa_pulchra = c(0, 0, 1.25, 
    0, 0.5, 0, 1.25, 1.75, 4.583333333, 0, 0, 1.25, 4.583333333, 
    0, 0), Achillea_millefolium = c(7.5, 3.333333333, 5, 3.416666667, 
    9.166666667, 49.16666667, 22.91666667, 25.41666667, 8.75, 
    34.33333333, 14.16666667, 4.166666667, 10, 3.75, 12), Eschscholzia_californica = c(1.25, 
    0, 0, 2.916666667, 0, 0, 1.25, 0, 0, 0, 0.666666667, 1, 0, 
    1.583333333, 0), Lupinus_variicolor = c(0, 0, 0, 0, 0, 0, 
    0, 0, 2.5, 0, 0, 0, 0, 0, 0), Echium_candicans = c(0, 0, 
    0, 0, 0.666666667, 0, 0, 0, 0, 0, 1.25, 0, 0, 0, 0)), .Names = c("Avena_fatua", 
"Bromus_diandrus", "Bromus_hordeaceus", "Festuca_myuros", "Festuca_perennis", 
"Carduus_pycnocephalus", "Cirsium_vulgare", "Erodium_cicutarium", 
"Geranium_dissectum", "Helminthotheca_echioides", "Lactuca_serriola", 
"Medicago_polymorpha", "Oxalis_pes.caprae", "Raphanus_sativus", 
"Senecio_vulgaris", "Sonchus_oleraceus", "Vicia_sativa", "Artemisia_californica", 
"Baccharis_pilularis", "Ericameria_ericoides", "Mimulus_aurantiacus", 
"Bromus_carinatus", "Elymus_triticoides", "Hordeum_brachyantherum", 
"Stipa_pulchra", "Achillea_millefolium", "Eschscholzia_californica", 
"Lupinus_variicolor", "Echium_candicans"), row.names = c("PC1", 
"PC2", "PC3", "PC4", "PC5", "PS1", "PS2", "PS3", "PS4", "PS5", 
"PW1", "PW2", "PW3", "PW4", "PW5"), class = "data.frame")

> dput(nativetree)
structure(list(edge = structure(c(12L, 13L, 14L, 15L, 16L, 16L, 
15L, 14L, 17L, 18L, 18L, 19L, 19L, 17L, 13L, 12L, 20L, 21L, 21L, 
20L, 13L, 14L, 15L, 16L, 1L, 2L, 3L, 17L, 18L, 4L, 19L, 5L, 6L, 
7L, 8L, 20L, 21L, 9L, 10L, 11L), .Dim = c(20L, 2L)), edge.length = c(7.629639, 
22, 20.333344, 93.62796, 11.038696, 11.038696, 104.666656, 28.5, 
62.899994, 33.600006, 16.800003, 16.800003, 16.800003, 96.5, 
147, 41.985199, 51.760712, 60.883728, 60.883728, 112.64444), 
    Nnode = 10L, node.label = c("", "eudicots", "", "euasterids", 
    "", "eurosids", "mesopapilionoideaeclade", "lupinus", "", 
    ""), tip.label = c("achillea_millefolium", "ericameria_ericoides", 
    "mimulus_aurantiacus", "hosackia_gracilis", "lupinus_nanus", 
    "lupinus_variicolor", "sidalcea_malviflora", "eschscholzia_californica", 
    "bromus_carinatus", "nassella_pulchra", "sisyrinchium_bellum"
    ), root.edge = 291.370361), .Names = c("edge", "edge.length", 
"Nnode", "node.label", "tip.label", "root.edge"), class = "phylo", order = "cladewise")

问题是
海峡
原生树
之间的物种名称不匹配

intersect(row.names(STraits), nativetree$tip.label)
# character(0)
R
区分大小写,因此树中小写的名称不会被识别为与数据矩阵中大写的名称相同。此外,物种的名称也不同

一旦名称正确匹配,特征需要按上述顺序排列:

traits <- STraits[nativetree$tip.label,]
请注意,我使用您随
dput
提供的数据,而不是脚本中隐含的修改。此外,检查语法


如图所示,可使用
phytools
软件包在系统发育图上绘制连续特征

为SO社区提供数据时,复制函数的输出
dput
。例如,您的第四行将在第一个单元格中插入一个空列表。为了解决这个问题,我们需要
dput(海峡)
dput(Veg2018)
dput(nativetree)
。或者更好的是,创建一个。感谢您的建议,我真的不知道如何为phylogenty创建MVCE,但我已经在原始问题中添加了
dput
输出
intersect(row.names(STraits), nativetree$tip.label)
# character(0)
traits <- STraits[nativetree$tip.label,]
library(picante)
res = data.frame()
for(i in 1:ncol(traits)){
  res[i, ] = phylosignal(x = traits[, i], phy = nativetree, reps = 999)
}