在R中绘制multiphylo对象中的所有树

时间:2016-01-18 19:11:19

标签: r phylogeny

我是 R 的新手。 trees_file中有多个nexus格式的树:

library(ape)
trees <- read.nexus(“trees_file”)
#plot all trees in trees?

我尝试了plot(trees[1][[1]])lapply(trees, plot)

更新:

> str(trees)
Class "multiPhylo"
List of 5
 $ model_tree              :List of 4
  ..$ edge       : int [1:94, 1:2] 49 50 51 52 52 53 53 51 54 55 ...
  ..$ Nnode      : int 47
  ..$ tip.label  : chr [1:48] "t18" "t42" "t2" "t15" ...
  ..$ edge.length: num [1:94] 1e+35 1e+35 1e+35 1e+35 1e+35 ...
  ..- attr(*, "class")= chr "phylo"
  ..- attr(*, "order")= chr "cladewise"
 $ RF_supertree            :List of 3
  ..$ edge     : int [1:94, 1:2] 49 50 50 51 52 53 54 55 55 54 ...
  ..$ tip.label: chr [1:48] "t2" "t14" "t26" "t30" ...
  ..$ Nnode    : int 47
  ..- attr(*, "class")= chr "phylo"
  ..- attr(*, "order")= chr "cladewise"
 $ maximum_parsimony       :List of 3
  ..$ edge     : int [1:93, 1:2] 49 49 50 51 52 53 53 54 54 52 ...
  ..$ tip.label: chr [1:48] "t10" "t19" "t31" "t8" ...
  ..$ Nnode    : int 46
  ..- attr(*, "class")= chr "phylo"
  ..- attr(*, "order")= chr "cladewise"
 $ quart_supertree         :List of 3
  ..$ edge     : int [1:93, 1:2] 49 50 50 51 52 53 54 54 53 55 ...
  ..$ tip.label: chr [1:48] "t35" "t19" "t31" "t17" ...
  ..$ Nnode    : int 46
  ..- attr(*, "class")= chr "phylo"
  ..- attr(*, "order")= chr "cladewise"
 $ quartet_super_duper_tree:List of 3
  ..$ edge     : int [1:94, 1:2] 49 50 50 51 52 53 54 55 56 57 ...
  ..$ tip.label: chr [1:48] "t10" "t27" "t40" "t43" ...
  ..$ Nnode    : int 47
  ..- attr(*, "class")= chr "phylo"
  ..- attr(*, "order")= chr "cladewise"

> plot(trees[1][[1]])
Error in plot.window(...) : need finite 'xlim' values
> lapply(trees, plot)
Error in plot.window(...) : need finite 'xlim' values

这是trees_file

#nexus

Begin trees;

tree model_tree = ((((t18:99999999999999996863366107917975552.000000,(t42:99999999999999996863366107917975552.000000,t2:99999999999999996863366107917975552.000000):99999999999999996863366107917975552.000000):99999999999999996863366107917975552.000000,(((t15:99999999999999996863366107917975552.000000,(t37:99999999999999996863366107917975552.000000,t21:99999999999999996863366107917975552.000000):99999999999999996863366107917975552.000000):99999999999999996863366107917975552.000000,(((t5:99999999999999996863366107917975552.000000,t48:99999999999999996863366107917975552.000000):99999999999999996863366107917975552.000000,(t40:99999999999999996863366107917975552.000000,t33:99999999999999996863366107917975552.000000):99999999999999996863366107917975552.000000):99999999999999996863366107917975552.000000,(t1:99999999999999996863366107917975552.000000,t35:99999999999999996863366107917975552.000000):99999999999999996863366107917975552.000000):99999999999999996863366107917975552.000000):99999999999999996863366107917975552.000000,((t38:99999999999999996863366107917975552.000000,(t17:99999999999999996863366107917975552.000000,(t44:99999999999999996863366107917975552.000000,t6:99999999999999996863366107917975552.000000):99999999999999996863366107917975552.000000):99999999999999996863366107917975552.000000):99999999999999996863366107917975552.000000,t3:99999999999999996863366107917975552.000000):99999999999999996863366107917975552.000000):99999999999999996863366107917975552.000000):99999999999999996863366107917975552.000000,(((t20:99999999999999996863366107917975552.000000,t16:99999999999999996863366107917975552.000000):99999999999999996863366107917975552.000000,(t12:99999999999999996863366107917975552.000000,(((t13:99999999999999996863366107917975552.000000,t28:99999999999999996863366107917975552.000000):99999999999999996863366107917975552.000000,((t31:99999999999999996863366107917975552.000000,t7:99999999999999996863366107917975552.000000):99999999999999996863366107917975552.000000,((t32:99999999999999996863366107917975552.000000,t43:99999999999999996863366107917975552.000000):99999999999999996863366107917975552.000000,t19:99999999999999996863366107917975552.000000):99999999999999996863366107917975552.000000):99999999999999996863366107917975552.000000):99999999999999996863366107917975552.000000,t23:99999999999999996863366107917975552.000000):99999999999999996863366107917975552.000000):99999999999999996863366107917975552.000000):99999999999999996863366107917975552.000000,((((t10:99999999999999996863366107917975552.000000,t46:99999999999999996863366107917975552.000000):99999999999999996863366107917975552.000000,t47:99999999999999996863366107917975552.000000):99999999999999996863366107917975552.000000,(t4:99999999999999996863366107917975552.000000,t25:99999999999999996863366107917975552.000000):99999999999999996863366107917975552.000000):99999999999999996863366107917975552.000000,((t30:99999999999999996863366107917975552.000000,t8:99999999999999996863366107917975552.000000):99999999999999996863366107917975552.000000,t14:99999999999999996863366107917975552.000000):99999999999999996863366107917975552.000000):99999999999999996863366107917975552.000000):99999999999999996863366107917975552.000000):99999999999999996863366107917975552.000000,((((t36:99999999999999996863366107917975552.000000,t34:99999999999999996863366107917975552.000000):99999999999999996863366107917975552.000000,(((t45:99999999999999996863366107917975552.000000,t27:99999999999999996863366107917975552.000000):99999999999999996863366107917975552.000000,t29:99999999999999996863366107917975552.000000):99999999999999996863366107917975552.000000,(t22:99999999999999996863366107917975552.000000,t24:99999999999999996863366107917975552.000000):99999999999999996863366107917975552.000000):99999999999999996863366107917975552.000000):99999999999999996863366107917975552.000000,((t26:99999999999999996863366107917975552.000000,(t9:99999999999999996863366107917975552.000000,t11:99999999999999996863366107917975552.000000):99999999999999996863366107917975552.000000):99999999999999996863366107917975552.000000,t39:99999999999999996863366107917975552.000000):99999999999999996863366107917975552.000000):99999999999999996863366107917975552.000000,t41:99999999999999996863366107917975552.000000):99999999999999996863366107917975552.000000);

tree RF_supertree = ((t2,(((((t14,t26),(t30,t33)),(t8,(((t11,t21),(((t24,(t25,(((t42,t45),(t48,t38)),t20))),(t44,t39)),((t17,(t19,t40)),t10))),(((((t46,(t1,t43)),t29),t27),(t37,(((t35,t3),t9),(t15,t22)))),(((t4,t31),t6),t13))))),t28),((((t16,t23),t36),((t12,((t34,t41),t32)),t47)),(t7,t5)))),t18);

tree maximum_parsimony = (t10,((((t19,(t31,t8)),(t17,(t18,t21))),((((t48,t38),t42),t3),(t20,t44))),(((((t23,t16),t36),((t11,t2),(t34,t39))),(t26,t33)),((((((((t28,t6),(((t41,((t46,t32),t47)),t4),t30)),t5),t43),(t7,((((t15,t22),t12),t9),t25))),t14),t40),(t27,((t13,t1),t35))))),((t37,t29),(t24,t45)));

tree quart_supertree = ((t35,((((t19,t31),(((t17,(t18,(t43,((t3,t15),t22)))),t28),(t24,(((((((t11,(t1,t13)),t16),t21),t12),t20),t25),(t14,t26))))),t2),((((((((((((((t5,t8),(t34,(t6,(t9,t45)))),t47),t42),t41),t4),(((t40,(t46,t7)),t32),t27)),t44),t30),t23),t37),t36),t33),t29))),t39,((t38,t48),t10));

tree quartet_super_duper_tree = ((t10,((((((((((t27,t40),((((((((t43,t14),((t28,t4),t5)),(t15,t3)),t36),t31),(((((t41,((t32,(t47,t46)),t30)),t34),t2),t6),t7)),(((t16,t8),t33),t12)),(((t17,t18),t22),t26))),t23),(t35,t9)),t21),t25),t20),(t11,((t48,(t38,t1)),(t29,t37)))),t19),((((t39,t44),t13),t24),t45))),t42);

end;

1 个答案:

答案 0 :(得分:1)

在那个过去,我通过使用for循环将树打印到PDF中的单个页面来完成此操作。

例如:

pdf("my_trees.pdf")
for(i in 1:length(trees)){
    plot(trees[[i]])
}
dev.off()

树存储为列表,您需要访问整个树对象以进行绘图,这就是为什么您需要在for循环中使用双方括号,而不是根据您之前的尝试使用[1][1]

这实际上是lapply所做的,但通过将其保存到pdf中的页面,您将能够看到每棵树。如果您不保存为PDF(或其他格式),R每次都会覆盖以前的绘图 - 这可能是您留下一个绘图的原因。