[英]Putting Labels Inside Nodes in R ggraph package
I am trying to visualize a network using ggraph.我正在尝试使用 ggraph 可视化网络。 My code is as follows:
我的代码如下:
ggraph(x, layout = "fr") +
geom_edge_link(aes(width = weight), alpha = 0.50, edge_color = "grey20") +
geom_node_point(color = "black", size = 12, show.legend = FALSE, family = "serif") +
geom_node_label(aes(label = name),
repel = TRUE, show.legend = FALSE, family = "serif") +
theme_graph(background = "white")
It results in the following snippet of network plot:它会产生以下网络 plot 的片段:
Is it possible to create labels inside the nodes in ggraph?是否可以在 ggraph 的节点内创建标签? I tried geom_node_label and geom_node_text but none of them works that way.
我尝试了 geom_node_label 和 geom_node_text 但它们都不是那样工作的。 I also upload an example of what I have in mind below:
我还在下面上传了一个我想到的例子:
I would really appreciate your help.我将衷心感谢您的帮助。 I wish everyone a healthy summer.
祝大家有个健康的夏天。
geom_node_text()
is correct. geom_node_text()
是正确的。 the text was hidden as it was black on black.文本被隐藏,因为它是黑底黑字。
x <- data.frame('from' = c(1,2,3,4), 'to' = c(3,3,1,1), 'weight' = c(1,1,1,1))
ggraph(x, layout = "fr") +
geom_edge_link(aes(width = weight), alpha = 0.50, edge_color = "grey20") +
geom_node_point(color = "black", size = 12, show.legend = FALSE, family = "serif") +
geom_node_text(aes(label = name), colour = 'white', size=10,
show.legend = FALSE, family = "serif") +
theme_graph(background = "white")
gives this plot给出这个 plot
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.