Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Improving layout and resolution of a network graph in R

Tags:

r

igraph

Okay, so I made a plot in R. And I zoomed it as well. Apparently, I am not able to save the zoomed version ( however, it also, doesnt seem to be much helpful ). I am attaching a link to the original image. What I want is that if I zoom in on the image through an external software, I dont lose the information or the pixels. Also, after using the inbuilt zoom given by R, I am not able to see the nodes because they are getting overlapped by many others. Any way I can improve the picture quality or atleast I can see all the nodes?

Here's the link:

https://www.dropbox.com/s/m4rdf7ux8yeogb4/Rplot.pdf

The file for which I made the plot is like,

   "X1" "X2"
"1" 10 123
"2" 4 186
"3" 12 1959
"4" 61 882
"5" 96 431
"6" 14 1617
"7" 37 1536
"8" 17 292
"9" 17 768
"10" 17 2049
"11" 39 1437
"12" 5 25
"13" 36 592
"14" 32 855
"15" 10 1288
"16" 28 269
"17" 25 122 
"18" 142 147
"19" 792 1369
"20" 21 801
"21" 837 1004
"22" 1004 1924
"23" 515 1004
.............
"175" 356 2303
"176" 83 326

The code that I used to make the plot is as follows:

 library(igraph)
 gg7 <- graph.edgelist(cbind(as.character(wt$X1), as.character(wt$X2)), 
                 directed=F)
 sum(clusters(gg7)$csize>2)         
 plot(gg7)

Here, the name of the file is "wt".

like image 385
user3797829 Avatar asked Nov 01 '22 20:11

user3797829


1 Answers

You can use the plot and layout options (see link to igraph.plotting on the plot.igraph help page and also the help for layout) to reduce overlap and increase readability. Also, saving your plot as a PDF file will allow you to zoom in as much as you like. Here are two example layouts with fake data. I've adjusted only the layout and the vertex size, but there are many other options.

library(igraph)

set.seed(20)
wt2 = data.frame(X1=sample(1:100,200,replace=TRUE), X2=sample(1:100,200,replace=TRUE))
gg7 <- graph.edgelist(cbind(as.character(wt2$X1), as.character(wt2$X2)), 
                      directed=F)       

pdf("plot.pdf",10,10)
igraph.options(plot.layout=layout.circle, vertex.size=5)
plot(gg7)
dev.off()

enter image description here

pdf("plot2.pdf",10,10)
igraph.options(plot.layout=layout.graphopt, vertex.size=7)
plot(gg7)
dev.off()

enter image description here

like image 87
eipi10 Avatar answered Nov 08 '22 05:11

eipi10