-->

自由地放置顶点标签顶点以外用于R的圆图(Freely placing vertex labels o

2019-09-29 03:55发布

我目前正试图与放置每个节点的标签旁边的能力,以显示R的圆曲线,但是,节点本身之外。

我看了几个答案,并试图其中一个建议,我指定弧度通过每个节点本身给出的位置:

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:n, direction=-1, start=0)
plot(sev, layout=la, vertex.size=25, vertex.label.dist=5,
     vertex.label.degree=lab.locs, vertex.label.color="black")

而这主要是工作,但标签没有精确地放置的愿望(不是一个大问题),但我不能调整与CEX字体的大小(这最终是一个足够大的问题,我决定寻找其他方法)。

寻找一些更多的答案后,我能够发现存在下列命令:文本(“标签”,定位器(1)),这是应该允许交互放置文本用鼠标指针。 然而,当我跑,我得到以下错误:

In xy.coords(x, y, recycle = TRUE) : NAs introduced by coercion

我只是想分别与七个,八节点饼图做到这一点,所以这里是我正在与七个节点进行测试:

##testing graph labeling
library(igraph)
library(ggplot2)
library(scales)

##making a 7-node circle graph
sev=make_graph(c(1,2, 2,3, 3,4, 4,5, 5,6, 6,7, 7,1))
sev=as.undirected(sev)
#relabel specific nodes blue
j=1;#index of vertex to start coloring
 V(sev)$color="white"; #Need to default to white, otherwise will color all  blue
V(sev)$color[(j)%%7]="dodgerblue";
V(sev)$color[(j+1)%%7]="dodgerblue";
V(sev)$color[(j+2)%%7]="dodgerblue";
la<-layout.circle(sev)
plot(sev)
text("label",locator(1))

我提前道歉对任何格式的困难,我可能会编辑的问题来调整这些。

Answer 1:

看你的两个版本。

第二个版本, text(locator(1),"label")应该让你手工放置标签。

但是,你的第一个版本没有看起来那么糟糕。 因为你的第二个版本,把标签的节点里面,我有移动的标签,并取得了字体的两倍大,是想说明如何做到这一点( vertex.label.cex而不是cex )。 我不知道你想要的大小,但你应该可以从这里进行调整。

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:n, direction=-1, start=0)
plot(sev, layout=la, vertex.size=25, vertex.label.dist=0,
     vertex.label.degree=lab.locs, vertex.label.color="black", 
     vertex.label.cex=2)



文章来源: Freely placing vertex labels outside of vertices for a circle graph in R