ggraph:根据属性的顶点位置
ggraph: Vertex position according to attribute
假设我有一个如下所示的 igraph
图表:
library(ggraph)
library(igraph)
vertices <- data.frame(name = LETTERS[1:6],
time = c(0, 9, 9, 10, 10, 10))
edges <- data.frame(from = c("A", "B", "B", "A", "C", "C"),
to = c("B", "D", "E", "C", "E", "F"))
graph <- graph_from_data_frame(edges,
directed = TRUE,
vertices = vertices)
为了目前的目的,图表将始终是树或 DAG,我想使用 ggraph
以树状布局绘制图表。我的问题是:How to plot this graph with the time
vertex attribute for y-values?
我可以在 geom_node_point
中设置 aes(y = time)
以正确定位节点,但边缘不跟随:
ggraph(graph, layout = "tree") +
geom_node_point(aes(y = time)) +
geom_edge_link() +
theme_bw()
由 reprex package (v0.3.0)
于 2019-11-17 创建
在 geom_edge_link
中将 y
或 yend
美学设置为 time
会引发错误。
我是 ggraph
的新手,所以我不知道如何处理这个问题。
它并不漂亮,但您可以通过创建自己的布局来实现。
LO = layout_as_tree(graph)
LO[, 2] = V(graph)$time
ggraph(graph, layout = LO) +
geom_node_point() +
geom_edge_link() +
theme_bw()
假设我有一个如下所示的 igraph
图表:
library(ggraph)
library(igraph)
vertices <- data.frame(name = LETTERS[1:6],
time = c(0, 9, 9, 10, 10, 10))
edges <- data.frame(from = c("A", "B", "B", "A", "C", "C"),
to = c("B", "D", "E", "C", "E", "F"))
graph <- graph_from_data_frame(edges,
directed = TRUE,
vertices = vertices)
为了目前的目的,图表将始终是树或 DAG,我想使用 ggraph
以树状布局绘制图表。我的问题是:How to plot this graph with the time
vertex attribute for y-values?
我可以在 geom_node_point
中设置 aes(y = time)
以正确定位节点,但边缘不跟随:
ggraph(graph, layout = "tree") +
geom_node_point(aes(y = time)) +
geom_edge_link() +
theme_bw()
由 reprex package (v0.3.0)
于 2019-11-17 创建在 geom_edge_link
中将 y
或 yend
美学设置为 time
会引发错误。
我是 ggraph
的新手,所以我不知道如何处理这个问题。
它并不漂亮,但您可以通过创建自己的布局来实现。
LO = layout_as_tree(graph)
LO[, 2] = V(graph)$time
ggraph(graph, layout = LO) +
geom_node_point() +
geom_edge_link() +
theme_bw()