0

我在 R 中使用 ggnet 绘制网络

ggnet2(net2,  label = F,  palette = col, alpha = 0.75, size = 4, edge.alpha = 0.5, label.size = 2, node.color = "category")

这工作正常,但标签彼此重叠。由于我不想要所有标签,因此我尝试使用 geom_text_repel() 在名为 category 的列中指定一些标签。但是我收到一个错误。


head(ggnetwork(net2))
           x         y  category                          vertex.names       xend      yend
72 0.1527696 0.5879314 microRNAs Dpu-Mir-96-P3_LQNS02278075.1_32307_3p 0.07407189 0.6413515
73 0.1527696 0.5879314 microRNAs Dpu-Mir-96-P3_LQNS02278075.1_32307_3p 0.07355453 0.6360147
74 0.1527696 0.5879314 microRNAs Dpu-Mir-96-P3_LQNS02278075.1_32307_3p 0.02863141 0.6139941
75 0.1527696 0.5879314 microRNAs Dpu-Mir-96-P3_LQNS02278075.1_32307_3p 0.02474171 0.6064790
76 0.1527696 0.5879314 microRNAs Dpu-Mir-96-P3_LQNS02278075.1_32307_3p 0.11799126 0.6751930
77 0.1527696 0.5879314 microRNAs Dpu-Mir-96-P3_LQNS02278075.1_32307_3p 0.06962854 0.6256732

#Label the nodes when category==microRNAs using the names from column vertex.names
ggnet2(net2,  palette = col, alpha = 0.75, size = 4, edge.alpha = 0.5, label.size = 2, node.color = "category") + geom_text_repel(data= ggnetwork(net2)[ggnetwork(net2)$category == "microRNAs",], aes(label=ggnetwork(net2)$vertex.names))

Error: Aesthetics must be either length 1 or the same as the data (1465): label
Run `rlang::last_error()` to see where the error occurred.
4

0 回答 0