问题标签 [data.tree]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
669 浏览

r - 如何用 R 中的值可视化 data.tree?

如标题中所述,如何绘制具有相关值的 data.tree?

预先感谢您的帮助。已经不知所措了:(

编辑:更多信息:

我试图可视化的数据是一项调查,受访者被问到主要问题,如果他/她回答是,那么第一个问题就会有后续问题。我正在尝试可视化对每个问题回答是或否的受访者百分比,我的想法是使用类似图的决策树。

编辑:

Gilean 尝试了您的解决方案,效果很好,但是,如何让子节点将相同的单词识别为不同的树?以及如何通过字体大小或对齐方式调整单词,使其不会妨碍可视化?

0 投票
1 回答
37 浏览

r - R:操作列表名称

这是我最小的可重现示例:

电流输出:

我想知道是否有一种编程方式可以替换此列表中的$1to[[1]]$2to [[2]]?所以让输出看起来像这样,因为这是在将列表转换为 JSON 时制作数组的重要步骤。

这是我尝试过但没有以正确方式工作的方法: lapply(temp$rows$1, unname)

谢谢!

0 投票
1 回答
143 浏览

r - 按级别绘制 data.tree 着色和标签

我有以下 data.tree 结构。

根据图表和 ,这棵树具有三个不同的级别alltree$Get(function(x) c(level = x$level))

在此处输入图像描述

格式化此图时,我想实现两件事:

  1. 对盒子逐级着色,
  2. 逐个标签。

在此处输入图像描述

即使我尝试过,我也不知道如何访问这些级别。在这种情况下,我有“命名”节点,但我拥有的所有树都不是这种情况,所以我想通过它的级别号来访问它们。

0 投票
2 回答
132 浏览

r - 在 Shiny 中将 DiagrammeR、data.tree 导出为图像 (png)

我正在尝试从 Shiny App 下载图像,该图像由 DiagrammeR 对象生成。

这是代码:

这会下载(有错误)一个.txt,显然是错误的。我正在尝试下载 .png 我也尝试过使用 appshot,但没有成功。

0 投票
0 回答
52 浏览

r - 如何将重复节点修剪到最近的共同祖先?数据树 R

我有一个表示为树的组织结构。

如果你注意到,树中的关系是一个孩子可以有多个父母。如下图所示,子公司 4 位于 4 个独特的基础分支之下。同样,子公司 3 位于 2 个独特的分支机构。

树形结构

我如何总结我的树,以便孩子坐在多个分支上的任何地方,我都可以在最早的共同祖先下查看该孩子。

因此,例如,子公司 4 需要位于 BIG CORP 之下,因为这是包含子公司 4 的所有分支机构的第一个共同祖先。同样,子公司 3 应直接在 ABC Inc. 下报告。

0 投票
1 回答
33 浏览

r - Labeling Parent ID then Merging Back with Dataframe

I am trying to label rows with the id of the row above it (their parent id). In the example below, I have a tibble with different things you would say to a person. They are classified into greetings, farewells, questions, etc. Assuming the first entry of each classification/group is the root, I am trying to label the first child (the second entry) with the ID of the root.

The code below is able to label the second child, however, the tibble I end up with is missing two entries because of a filter. The filter is important because, in reality, the dataset is more complicated, so it (most likely) needs to stay.

How can I merge back the newly labeled tibble back with the original tibble? Also, if there are ways to do this within a pipe chain, that's even better.

The end goal would be a dataframe that looks like:

The end goal is actually to turn an email thread into a tree structure. Labeling the first two emails is easy because they are the oldest and the second oldest. After that it becomes more complicated. The tricky part with gmail threads is they don't store the parent message (or I haven't found where it's stored). So you have to use the content of the message to label the parents. Additionally, using the timestamp of the email doesn't work either because people can reply individually to messages and start new branches where time doesn't relate to their position in the branch.

Not that this is important to the question above. If you know of something around this topic that would be cool too.

0 投票
1 回答
365 浏览

r - R-Shiny 中的 circlepackeR - 根据用户输入创建圆形包装图

我正在尝试circlepackeR根据用户输入制作图表。我想知道在我正在使用的包中是否有可能,我是否应该完全使用不同的方法,或者我的代码是否有错误。我已经盯着它太久了。

这是我想要完成的基础知识。当用户从选项中选择一个县时,出现selectInput()一个模式对话框,其中显示该所选县的种族/民族/性别构成的圆圈包装。在我尝试通过使用反应函数根据选择的输入过滤数据来对数据帧进行子集化之前,效果很好。当我将数据从反应式过滤器转换为节点时会出现错误(“下标越界”、“请提供 json 对象或列表”、“在没有活动反应式上下文的情况下不允许操作..”)

这是我的代码:

用户界面:

服务器:

这是我的数据:

这是我第一次尝试圆形包装。我缺少什么信息?

0 投票
1 回答
80 浏览

r - 数据树的递归聚合

我使用data.tree包来执行分析而不是嵌套列表,因为我的实际数据最终导致列表过于嵌套并且很难使用。

我根据这个问题汇总了样本数据。使用 R 聚合数据树上的值。在我自己的数据中,我有to, from, hours数据并且需要创建数据,该数据是从其父节点actual_hours的值中减去的子节点的总和。hours

我不确定该怎么做,因为它涉及树的向上和向下运动?我认为使用树的height和/或level属性是可行的方法,但不确定。

0 投票
1 回答
856 浏览

r - ` 在 R 中,“错误:尝试应用非函数”

下面我分享了一个代码,尝试在使用data.treeR 软件包创建的树中添加子节点后遇到错误。错误说“尝试应用非函数”,我不知道我提供的数据类型是否有问题,或者它是否与语法有关。

0 投票
0 回答
112 浏览

r - 向 data.tree 对象添加“填充”属性以用于 R 中的 collapsibleTree

我们一直在使用数据collapsibleTree()框来制作交互式、漂亮的分层系统树状图。但是我们遇到的问题是,在使用数据框时很难获得我们想要的自定义,并且从collapsibleTree文档看来,使用 data.tree 结构提供了更大的灵活性。例如,如果我们想用数据框为特定节点着色,我们需要做这样的事情:

这并不是一个真正好的解决方案,尤其是当生成的树有数百个或更多节点或更高级别的层次结构时。

我在data.tree中看到,我应该可以添加任意属性,但这似乎不起作用,至少它没有达到我想要的效果:

这只是将每个节点着色为“灰色”(如果我这样做了,则为红色original_as_tree$Boat$color)。理想情况下,我可以通过某种case_whenifelse调用以编程方式分配颜色。

这是我的示例数据的输出: