将vertex.label放置在igraph中的圆形布局之外 [英] Placing vertex.label outside a circular layout in igraph
本文介绍了将vertex.label放置在igraph中的圆形布局之外的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个圆形的图形.我希望将顶点标签显示在圆形区域之外.尝试在vertex.label.cex
和vertex.label.degree
周围播放,但是没有用.请指教!
I have a circular layout igraph. I want the vertex label to be displayed outside the circular region. Tried playing around the vertex.label.cex
and vertex.label.degree
but did not work. Please advice!
推荐答案
vertex.label.degree
需要进行一些认真(但很简单)的调整才能做到这一点.这是来自此要点的示例.这不是我的代码(我相信它是 @kieran 的代码),但这是一个完全正常的示例.
vertex.label.degree
takes some serious (but straightforward) tweaking to do this. Here's an example from this gist. It's not my code (it's @kieran's, I believe), but it's a fully working example.
### Here's one way to do it.
library(igraph)
library(ggplot2)
library(scales)
## The igraph docs say that vertex.label.degree controls the position
## of the labels with respect to the vertices. It's interpreted as a
## radian, like this:
##
## Value is : Label appears ... the node
## -pi/2: above
## 0: to the right of
## pi/2: below
## pi: to the left of
##
## We can generalize this. vertex.label.degree can take a vector as
## well as a scalar for its argument. So we write a function to
## calculate the right position for a label based on its vertex's location
## on the circle.
## Get the labels aligned consistently around the edge of the circle
## for any n of nodes.
## This code borrows bits of ggplot2's polar_coord function
## start = offset from 12 o'clock in radians
## direction = 1 for clockwise; -1 for anti-clockwise.
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)))
}
### Example
## Generate some fake data
n <- 15
g <- erdos.renyi.game(n, 0.5)
## Obviously labeling in this way this only makes sense for graphs
## laid out as a circle to begin with
la <- layout.circle(g)
lab.locs <- radian.rescale(x=1:n, direction=-1, start=0)
plot(g, layout=la, vertex.size=2, vertex.label.dist=1,
vertex.label.degree=lab.locs)
这篇关于将vertex.label放置在igraph中的圆形布局之外的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文