如何使 R 中 igraph 右侧的箭头线变短?

How to make the arrow lines shorter from right side of igraph in R?

我制作了一个 igraph 图,从左侧开始使用较短的线,但现在我想从右侧开始使用较短的线。这是数据:

dput(sample)
structure(list(NMSUKU = c("Aceh/ Achin/ Akhir/ Asji/ A-Tse/ Ureung Aceh", 
"Alas", "Aneuk Jamee", "Gayo", "Gayo Lut", "Gayo Luwes", "Gayo Serbe Jadi", 
"Kluet", "Sigulai", "Simeulue", "Simeulue", "Simeulue", "Singkil", 
"Singkil", "Tamiang"), TopLang = c("Aceh/ Acheh/ Achi ", "Alas ", 
"Aceh Jamee ", "Gajo/ Gayo ", "Gajo/ Gayo ", "Gajo/ Gayo ", "Gajo/ Gayo ", 
"Aceh Kluet ", "ERROR  TopCol out of range ", "Long Bano/ Simalur/ Simeuloe/ Simeulue/ Simulul ", 
"Aceh Simeleu Barat ", "Aceh Simeleu Tengah ", "Aceh Hulu Singkil ", 
"Aceh Hulu Singkil ", "Tamiang "), Ethnicity = c("1_Aceh/ Achin/ Akhir/ Asji/ A-Tse/ Ureung Aceh  ", 
"2_Alas  ", "3_Aneuk Jamee  ", "4_Gayo  ", "6_Gayo Luwes  ", 
"5_Gayo Lut  ", "7_Gayo Serbe Jadi  ", "8_Kluet  ", "NA  ", "10_Simeulue  ", 
"10_Simeulue  ", "10_Simeulue  ", "11_Singkil  ", "17_Batak Pakpak Dairi  ", 
"12_Tamiang  ")), row.names = c(NA, -15L), class = "data.frame")

这是使行从左侧变短的代码:

m <- as.matrix(replace(sample, sample == "", "NA"))
g <- simplify(graph_from_edgelist(rbind(m[, 1:2], m[, 2:3]), directed = TRUE))
l <- layout_with_sugiyama(g)
l$layout[, 2][l$layout[, 2] == 1] <- l$layout[, 2][l$layout[, 2] == 1] * 0.1 # this is the line change the horizontal coordinates for edges on the left part
plot(g,
  layout = -l$layout[, 2:1],
  edge.arrow.size = 0.1,
  vertex.size = 2.5,
  vertex.color = "grey",
  vertex.label.dist = 1,
  edge.arrow.width = 1.5,
  edge.width = seq(0.5, 0.08),
  edge.lty = "solid",
  edge.color = "gray",
  vertex.label.cex = 0.7,
  is.rm = TRUE,
  vertex.label.color = "black"
)

现在我想从右侧缩短线条。谢谢!

您可以在左侧部分的边缘添加权重,即

m <- as.matrix(replace(sample, sample == "", "NA"))
g <- simplify(graph_from_edgelist(rbind(m[, 1:2], m[, 2:3]), directed = TRUE))
l <- layout_with_sugiyama(g)
l$layout[, 2][l$layout[, 2] == 1] <- l$layout[, 2][l$layout[, 2] == 1] * 1.8 # this is the line changing the horizontal coordinates for edges on the right part
plot(g,
  layout = -l$layout[, 2:1],
  edge.arrow.size = 0.1,
  vertex.size = 2.5,
  vertex.color = "grey",
  vertex.label.dist = 1,
  edge.arrow.width = 1.5,
  edge.width = seq(0.5, 0.08),
  edge.lty = "solid",
  edge.color = "gray",
  vertex.label.cex = 0.7,
  is.rm = TRUE,
  vertex.label.color = "black"
)

这给出了