首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在倾斜图中标记中心节点?

如何在倾斜图中标记中心节点?
EN

Stack Overflow用户
提问于 2022-03-28 09:05:19
回答 1查看 49关注 0票数 3

从另一个问题中使用这个可复制的例子。如何标记/着色本地邻域图所基于的中心节点。(在本例中为“x”)

代码语言:javascript
复制
library(tidygraph)
library(ggraph)


# Example
net <- tibble::tibble(A = letters[1:6],
                      B = rep(c("x", "y"), each = 3)) %>% 
  tidygraph::as_tbl_graph()

net %>%
  tidygraph::convert(to_local_neighborhood,
                     node = which(.N()$name == "x"),
                     order = 1,
                     mode = "all") %>%
  ggraph(layout = "nicely") +
  geom_edge_link() +
  geom_node_point(size = 10, fill = "white", shape = 21) +
  geom_node_text(aes(label = name)) +
  theme_graph()

我得到的是:

我想要的:

我觉得geom_node_point应该有条件填充,但我不知道这是否可能.

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-03-28 09:43:07

你可以:

代码语言:javascript
复制
net %>%
  tidygraph::convert(to_local_neighborhood,
                     node = which(.N()$name == 'x'),
                     order = 1,
                     mode = "all") %>%
  mutate(root = ifelse(node_is_center(), 'red', 'white')) %>%
  ggraph(layout = "nicely") +
  geom_edge_link() +
  geom_node_point(size = 10, aes(fill = root), shape = 21) +
  geom_node_text(aes(label = name)) +
  scale_fill_identity() +
  theme_graph()

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71644885

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档