Reputation: 773
I am plotting a network using ggnet in R
ggnet2(net2, label = F, palette = col, alpha = 0.75, size = 4, edge.alpha = 0.5, label.size = 2, node.color = "category")
This works fine but the labels are on top of each other. Since I do not want all the labels, just a few specified in a column called category I am trying to use geom_text_repel(). However I am getting an error.
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.
Upvotes: 0
Views: 303