我有以下data.frame。
library(tidyverse)
library(ggraph)
library(tidygraph)
df <- structure(list(from = c(3L, 3L, 1L, 1L, 1L, 3L, 3L, 3L, 3L, 2L,
2L, 1L, 3L, 1L, 3L, 3L, 3L, 1L, 3L, 3L, 2L, 3L, 3L, 2L, 3L, 3L,
1L, 3L, 1L, 1L, 2L, 1L, 2L, 3L, 1L, 1L, 3L, 1L, 1L, 3L, 1L, 2L,
3L, 3L, 3L, 3L, 3L, 1L, 1L, 3L, 1L, 3L, 3L, 3L, 3L, 1L, 2L, 1L,
3L, 1L, 3L, 1L, 1L, 1L, 1L, 3L, 1L, 1L, 2L, 3L, 1L, 1L, 1L, 1L,
1L, 1L, 3L, 3L, 2L, 3L, 3L, 1L, 3L, 1L, 1L, 1L, 1L, 1L, 3L, 3L,
3L, 3L, 1L, 1L, 1L, 1L, 2L, 2L, 1L, 2L), to = c(31L, 21L, 5L,
97L, 68L, 49L, 3L, 84L, 17L, 335L, 1L, 6L, 207L, 2L, 3L, 457L,
3L, 149L, 17L, 3L, 41L, 126L, 89L, 150L, 42L, 262L, 235L, 79L,
335L, 2L, 104L, 445L, 10L, 79L, 5L, 7L, 3L, 39L, 6L, 402L, 123L,
104L, 246L, 448L, 261L, 44L, 47L, 170L, 158L, 435L, 39L, 47L,
11L, 31L, 18L, 236L, 144L, 237L, 106L, 236L, 19L, 393L, 104L,
6L, 440L, 191L, 171L, 302L, 255L, 134L, 197L, 373L, 68L, 10L,
1L, 6L, 461L, 28L, 216L, 473L, 108L, 238L, 79L, 1L, 11L, 178L,
432L, 5L, 3L, 91L, 449L, 26L, 123L, 456L, 73L, 1L, 105L, 432L,
160L, 10L), time = c(2, 1, 3, 3, 1, 3, 1, 1, 1, 2, 3, 1, 1, 1,
1, 3, 3, 2, 1, 1, 1, 3, 1, 1, 2, 2, 2, 3, 2, 1, 3, 3, 1, 3, 3,
1, 2, 1, 1, 3, 3, 2, 2, 3, 3, 1, 1, 3, 1, 3, 1, 1, 1, 3, 3, 2,
1, 3, 3, 2, 3, 3, 1, 1, 3, 1, 1, 3, 2, 3, 3, 3, 1, 2, 2, 2, 3,
1, 1, 3, 1, 2, 3, 1, 1, 3, 3, 1, 3, 1, 3, 2, 3, 3, 2, 3, 1, 3,
3, 1)), class = c("tbl_df", "tbl", "data.frame"), row.names = c(NA,
-100L))
g <- df %>% graph_from_data_frame()
然后此代码产生一个ggraph
g %>%
as_tbl_graph() %>%
activate(nodes) %>%
mutate(degree = centrality_degree()) %>%
ggraph()+
geom_edge_fan(aes(color = time))+
geom_node_point(aes(size = degree),
show.legend = F)+
coord_equal()+
facet_edges(~time, drop = T)+
theme_graph()
我的问题是:如何删除图中各面中的无边节点,以使只有具有边的节点出现在每个面中?
谢谢!