给定以下示例代码,
library(tidyverse)
library(tidygraph)
library(ggraph)
reprex <- tibble(to = 1:10,
from = c(2:10, 1),
facet = rep(1:2, each = 5)) %>%
as_tbl_graph()
reprex_plot <- reprex %>%
ggraph() +
geom_node_point() +
geom_edge_link()
reprex_plot + facet_edges(~ facet)如何隐藏没有边缘进入或退出节点的节点?
发布于 2018-10-04 16:15:11
library(tidyverse)
library(tidygraph)
library(ggraph)
reprex2 <- tibble(to = 1:10,
from = c(2:10, 1)) %>%
as_tbl_graph() %>%
activate(nodes) %>%
mutate(facet = rep(1:2, each = 5))
reprex_plot <- reprex2 %>%
ggraph() +
geom_node_point() +
geom_edge_link() +
geom_node_label(aes(label = name)) +
theme_graph() +
facet_nodes(~ facet)
reprex_plot我可以理解您的方法,但tidygraph的as_tbl_graph()的智能带来了困难。您传递的本质上是一个边缘列表,其中facet是一个只适用于边缘的变量。您可以通过执行reprex %>% activate(nodes) %>% as_tibble()来验证这一点,以确保facet列与节点没有关联。
我的解决方案是在节点上显式地构造facet列,然后使用facet_nodes(),这是facet_edges()的逆序。
如果终端节点都在面板中,则绘制边缘。
https://stackoverflow.com/questions/46466351
复制相似问题