将顶点标签放置在圆形图的外部,以改变尺寸的顶点和尺寸的标签

时间:2019-06-27 16:15:13

标签: r igraph

我试图将顶点的标签放置在圆形图之外。我已经阅读了很多有关Placing vertex.label outside a circular layout in igraphFreely 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)

设置放置位置时,是否可以考虑顶点大小?

此外,不管字符串有多长,标签都可以完全不在顶点之外吗?

1 个答案:

答案 0 :(得分:0)

您已将vertex.label.dist指定为常数,但是它可以是向量,因此每个顶点的偏移量都不同。通过简单的顶点大小函数,我得到了很好的结果。您也许可以尝试并获得更好的结果。

plot(home_weighted_net, layout= lay,  vertex.label.degree=lab.locs,
     vertex.label.dist= points/4+2.5)

Vertex labels with different offsets