Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/67.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在ggraph中隐藏未连接的节点_R_Tidyverse_Ggraph_Tidygraph - Fatal编程技术网

如何在ggraph中隐藏未连接的节点

如何在ggraph中隐藏未连接的节点,r,tidyverse,ggraph,tidygraph,R,Tidyverse,Ggraph,Tidygraph,给出以下示例代码 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()

给出以下示例代码

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)
库(tidyverse)
图书馆(潮汐图)
图书馆(ggraph)
雷普雷克斯%
as_tbl_图()
reprex_地块%
ggraph()+
几何节点点()+
geom_边缘_链接()
reprex_图+面_边(~facet)
如何隐藏没有进出节点边缘的节点?

库(tidyverse)
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
图书馆(潮汐图) 图书馆(ggraph) reprex2% 如图()%>% 激活(节点)%>% 突变(小平面=重复(1:2,每个=5)) reprex_地块% ggraph()+ 几何节点点()+ geom_边缘_链接()+ geom_节点_标签(aes(标签=名称))+ 主题图() 面\节点(~facet) 雷普雷克斯图
我可以理解你的方法,但困难在于
tidygraph
作为
的智能。实际上,您传递的是一个边列表,其中facet是一个仅应用于边的变量。您可以通过执行
reprex%%>%activate(nodes)%%>%as_tible()
来验证这一点,以查看facet列与节点没有关联

我的解决方案是在节点上显式构造facet列,然后使用
facet\u nodes()
,这与
facet\u edges()相反

如果其端子节点都存在于配电盘中,则会绘制边


你找到解决办法了吗?没有。我最近没有做任何网络策划,所以我没有真正追求它。感谢您的回复。这将很难实施。我试过了。我可以删除孤立的节点,但每种情况下的布局都不同。没有帮助。我认为在geom_edge_link()中只显示连接的节点是很酷的。我认为部分解决方案是使用类似mutate(node_edge_description=.E()$edge_description)的方法将边缘数据应用于节点,然后按节点和边缘进行镶嵌……不确定