我是 R 新手。
我想创建一个巨大的树图来表示 R 中的乐透游戏,看起来像这张图片中的树图 1(我通过 PowerPoint 制作的):
问题是我需要从 45 个球中抽出 6 个球。本例中的总元素为 127。我尝试使用 PowerPoint 创建树形图,它看起来像树形图 2。
然后我放弃了。我无法输入“匹配”和“不匹配”并手动计算如此庞大的图表的概率。
如何创建与树图 2 相似且在树图 1 中具有相似标签的树图?
该DiagrammeR包应该会有所帮助:
library(DiagrammeR)
nodes <- create_nodes(nodes = 1:7, type = "number")
edges <- create_edges(from = c(1, 1, 2, 2, 3, 3),
to = c(2, 3, 4, 5, 6, 7),
rel = "leading to")
graph <- create_graph(nodes_df = nodes,
edges_df = edges,
graph_attrs = "layout = dot",
node_attrs = "fontname = Helvetica",
edge_attrs = "color = gray20")
# View the graph
render_graph(graph)
Run Code Online (Sandbox Code Playgroud)
您可以相应地“喜欢”编程和标签:
nodes <- create_nodes(nodes = 1:7, type = "number",
label = c("Lotto", rep(c("match", "no match"), times = 3)))
### Same Code as Above...
Run Code Online (Sandbox Code Playgroud)