旋转顶点标签

7
使用igraph包绘制图表时,如何旋转绘图中的顶点标签,例如旋转 π/4?
library(igraph)
g = graph.ring(5)
V(g)$name = paste(LETTERS[1:5], 'rotate_45')
plot.igraph(vertex.label.rotate=pi/2, g ) ##this doesn't work

plot.igraph(vertex.label.degree = pi/2, g) 可能是这样的吗? - David Arenburg
@DavidArenburg vertex.label.degree: 标签相对于顶点的位置,其中0表示右侧,“pi”表示左侧,“pi/2”表示下方,“-pi/2”表示上方。 这是指标签的位置,而不是字符的方向。 - YJZ
1个回答

0
据我所知,这在igraph中是不可能直接实现的。然而,通过指定布局,我们可以获取顶点的坐标并添加旋转的文本。
library(igraph)
g = graph.ring(5)
V(g)$name = paste(LETTERS[1:5], 'rotate_45')

#add layout to have coordinates where we can plot the vertices labels later
coords <- layout_(g, in_circle())

plot.igraph(g, layout = coords,  vertex.label = "", rescale = F)

angles = c(45, 45, 45, 135, 77)

#Apply the text labels with angle as srt
for (i in 1:dim(coords)[1]) {
  text(x = coords[i,1], y = coords[i,2], labels = V(g)$name[i], 
       col = "black", srt = angles[i], xpd = T)
}

这将导致: {{link1:在此输入图像描述}}
如果您想提供弧度,您可以在指定角度之前使用。
rad2deg <- function(rad) {(rad * 180) / (pi)}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接