在R中绘制文本注释

时间:2014-08-19 15:32:30

标签: r plot igraph

我正在尝试在绘制igraph图形对象时向网络添加文本注释。我提供了一个玩具示例 - 我无法在(x,y)位置显示任何文本。有人可以修改它以使其正常工作吗?

TestAnnoDir <- getwd()

myText <- data.frame(x=seq(2,20,2), y=seq(2,20,2), text= sample(state.name, 10))
fn <- paste(TestAnnoDir, "Test", ".tif",sep="")
tiff(filename = fn, width = 1000, height = 1000)

# toy network example
erdos.renyi = erdos.renyi.game(10, 1/2, directed=FALSE)
plot( erdos.renyi ,
     vertex.size = 3,
     vertex.label = "", 
     vertex.label.color = "black" 
) 

#plot.new()
for(i in 1: nrow(myText)){
  text(x=myText[i,"x"],y=myText[i,"y"], labels=myText[i,"text"])
} 
dev.off()

P.S。我在RStudio中做这件事

1 个答案:

答案 0 :(得分:0)

啊......看起来画布在x,y

中的-1,1缩放

所以这会起作用:

text(0, 0,"0,0")
text(0, 1,"0,1")
text(0, -1,"0,-1")
text(-1, -1,"-1,-1")
text(1, -1,"1,-1")
text(1, 1,"1,1")
text(-1, 1,"-1,1") 

看起来像 enter image description here