我试图将顶点的标签放置在圆形图之外。我已经阅读了很多有关Placing vertex.label outside a circular layout in igraph和Freely placing vertex labels outside of vertices for a circle graph in R的帖子。
问题是我的顶点缩放到了不同的大小,因此,无论顶点多大或小,将标签直接放置在顶点之外都无法按我的意愿工作。
我正在使用此问题的最高答案(Placing vertex.label outside a circular layout in igraph)中的代码来生成位置。
当我删除不同大小的节点时,标签沿正确的方向移动,但是其中一些标签并不完全在顶点外,因为某些名称太长。
# set up dummy data
players <- c("Jack Taylor", "John", "Mike", "Jackson Hubbard", "Matt", "Casey", "Adam")
points <- c(20, 10, 5, 8, 15, 12, 30)
stats <- data.frame(name = players, points = points)
from <- c("Jack Taylor", "Jackson Hubbard", "Adam", "Matt", "Jack Taylor", "John")
to <- c("John", "Jack Taylor", "Jackson Hubbard", "Adam", "Adam", "Casey")
count <- c(2, 3, 5, 2, 1, 1)
assists <- data.frame(from = from, to = to, count = count)
home_weighted_net <- graph_from_data_frame(d=assists, vertices=players, directed=T)
V(home_weighted_net)$size <- points * 3
V(home_weighted_net)$label.cex <- 0.5
E(home_weighted_net)$width <- assists$count
# generate positions and graph
radian.rescale <- function(x, start=0, direction=1) {
c.rotate <- function(x) (x + start) %% (2 * pi) * direction
c.rotate(scales::rescale(x, c(0, 2 * pi), range(x)))
}
lab.locs <- radian.rescale(x=1:7, direction=-1, start=0)
lay <- layout.circle(home_weighted_net)
plot(home_weighted_net, layout= lay, vertex.label.degree=lab.locs, vertex.label.dist= 2)
设置放置位置时,是否可以考虑顶点大小?
此外,不管字符串有多长,标签都可以完全不在顶点之外吗?