使用format()时,图表标签向右移动

时间:2013-11-25 01:41:24

标签: plot igraph

请考虑以下

g <- graph.ring(10)
V(g)$label[1:5] <- 10
V(g)$label[6:10] <- 100000000
plot(g, layout=layout.circle, vertex.label=format(V(g)$label, big.mark=",", scientific=FALSE))

输出

enter image description here

我想知道为什么前5个顶点的标签向右移动以及如何将它们带回节点的中心。

1 个答案:

答案 0 :(得分:1)

format的关系多于igraph

format(V(g)$label, big.mark=",", scientific=FALSE)
# [1] "         10" "         10" "         10" "         10" "         10"
# [6] "100,000,000" "100,000,000" "100,000,000" "100,000,000" "100,000,000"

只需删除空格,标签就会居中:

sub("[ ]+", "", format(V(g)$label, big.mark=",", scientific=FALSE))
# [1] "10"          "10"          "10"          "10"          "10"         
# [6] "100,000,000" "100,000,000" "100,000,000" "100,000,000" "100,000,000"