有的文章会在模块化的群落里加上Convex Hull ,类似这样,如何实现呢,可以借助ggforce的geom_mark_hul
比如我们的示例代码稍作修改
# add a Convex Hull library(ggforce) # for geom_mark_hull or geom_encircle p1 <- ggraph(g, layout = "fr") + geom_edge_link(aes(color = type, width = abs(as.double(correlation))), alpha = 0.9, show.legend = TRUE) + geom_node_point(aes(size = as.double(node.mean.abundance), fill = node.sub.module), alpha = 0.9, color = "#000000", show.legend = TRUE, shape = 21) + scale_size(range = c(2, 6), name = "degree") + scale_fill_manual(values = myColor, name = "module") + scale_edge_width_continuous(range = c(0.1, 0.3), name = "abs(correlation)") + scale_edge_colour_manual(name = "type", values = c(positive = "#e41a1c", negative = "#377eb8")) + theme_void() + geom_mark_hull(aes(x = x, y = y, group = node.sub.module, fill = node.sub.module), concavity = 1, expand = unit(5, "mm"), alpha = 0.1) # Adjust parameters as needed p1
得到的结果如下
其他参数可以看帮助调节
如果觉得我的文章对您有用,请随意打赏。你的支持将鼓励我继续创作!