Search code examples
rnetwork-programmingpngresolutionigraph

Improve the resolution of png generated with R


I created some networks through R and the IGRAPH package in .png files. My goal would be to make a little video to show how the topology of the network changes through the time. Only that the resolution of the .png files is really low. Is there a way that would generate the same file but with an higher resolution? My colleague with his PC and using the same R script generated networks with an higher resolution.

Here is my code:

wd<-getwd()
setwd(wd)
library(Matrix)
library(igraph)
library(slam)

plotname<-sprintf("g_communities_t%03d.png",t)
png(filename=plotname, height=640, width=640)
plot(community.infomap[[t]],g1[[t]],layout=layout.fruchterman.reingold,vertex.label=NA,edge.arrow.size=1,edge.curved=TRUE,vertex.size=2+sqrt(vertex.weight[[t]]))
dev.off()

Thanks to all


Solution

  • Use png's res parameter to adjust nominal resolution. Note that is a good idea to adjust values vor height and width accordingly in order to preserve text size etc.:

    resfactor = 3
    png(filename=plotname, res = 72*resfactor, height=640*resfactor, width=640*resfactor)
    

    ? png gives you more details (also see ? dev.copy to copy the graphics contents of the current device to another).