use*_*168 11 label r graph-theory igraph
我想移动边缘标签的位置,使其不在它的顶部.这是一个小例子:
g <- graph.empty(n=3)
g <- graph(c(1,2,3,2,1,3), directed=T)
E(g)$weight <- c(3,2,5)
plot(g, edge.label = E(g)$weight)
Run Code Online (Sandbox Code Playgroud)
在我的例子中,标签位于边缘,我希望它们垂直于边缘移动一点点.
很抱歉成为那个说“使用库(x)怎么样?”的人。
我的代码使用 ggraph?
library(igraph)
library(ggraph)
g <- graph.empty(n=3)
g <- graph(c(1,2,3,2,1,3), directed=T)
E(g)$weight <- c(3,2,5)
#your plot
plot(g, edge.label = E(g)$weight)
#using ggraph
ggraph(graph = g) +
geom_node_circle(size = 1, mapping = aes(r =0.03), fill="goldenrod") +
geom_edge_link(mapping = aes (label = weight),
arrow = arrow(type = "closed", angle = 15),
end_cap = circle(8, 'mm'), ,
start_cap = circle(8, 'mm'),
colour="grey",
label_dodge = unit(5, "mm"),
angle_calc = "along") +
geom_node_text(mapping = aes(label = "2")) +
theme_graph()
Run Code Online (Sandbox Code Playgroud)