【发布时间】:2019-01-07 13:18:56
【问题描述】:
我想将 R 对象(嵌套列表)可视化为一棵树。考虑以下列表
x <- list(
id = 1,
status = "active",
coord = list(phi=0, theta=1, r=1),
mt = NULL
)
我想查看它的结构,而不是实际值。我可以使用data.tree library 以迂回的方式实现这一点:
library(data.tree)
dt <- list(
name = "x",
children = list(
list(name = "id"),
list(name = "status"),
list(name = "coord",
children = list(
list(name = "phi"),
list(name = "theta"),
list(name = "r")
)
),
list(name = "mt")
)
)
plot(FromListExplicit(dt))
这是结果:
然而,这相当复杂。这种方法的问题是创建树状图的代码(对象dt)与我的实际代码(对象x)分离。随着我的代码的发展和我的对象的变化,我想让它们在当前状态下快速可视化(例如,在 Rmarkdown 文档中)。
有没有办法将嵌套列表的结构绘制为树?或者,也许有人可以建议一个函数将我的原始对象转换为适合data.tree 的列表,即将x 转换为dt。唉,我的遍历树的技术不是很好。
【问题讨论】:
标签: r list tree visualization