Reputation: 610
I'm trying to add text annotations to a network when plotting an igraph graph object. I provided a toy example - I can't get any of the text to show up in the (x,y) locations. Can someone modify this so that it works properly?
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. I'm doing this in RStudio
Upvotes: 1
Views: 958
Reputation: 610
Ah... Looks like the canvas is scaled on -1,1 in both x,y
so this will work:
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")
And looks like
Upvotes: 2