1

如何将颜色信息添加到 tbl_graph 的边缘?我想根据“to”和“from”节点的颜色为边缘着色:如果两个节点具有相同的颜色,那么它们之间的边缘应该具有相同的颜色。

library(tidyverse)
library(tidygraph)
library(ggraph)

create_notable('tutte') %>%
activate(nodes) %>%
mutate(group = as.factor(group_louvain())) %>%
ggraph() +
geom_node_point(aes(color=group),size=7) +
geom_edge_link()
4

1 回答 1

1

好的...我找到了答案!

g <- create_notable('tutte') %>%
  activate(nodes) %>%
  mutate(id = row_number(),
         group = as.factor(group_louvain()))

g <- g %>%
  activate(edges) %>%
  mutate(group_from = .N()$group[from],
         group_to = .N()$group[to]) %>%
  mutate(ge = ifelse( group_from == group_to, group_from, NA))




ggraph(g) +
  geom_node_point(aes(color=group),size=7) +
  geom_edge_link(aes(color = as.factor(ge)) )
于 2019-09-08T08:55:18.070 回答