Working with vertex size is not easy on igraph as that is a function of the plotting region itself. This can be solved by rescaling the vertex size considering the plotting region, further, as done in Gephi, users could provide vertex size and relative scale (minimum/maximum sizes) to the plotting area (e.g. 0.5% and 1.0% of the plotting area). The following code does exactly that:
rescale_vertex_igraph <- function(
vertex.size,
par.usr=par("usr"),
minmax.relative.size=c(.05,.01),
adjust=200
) {
if (!length(vertex.size)) return(
rescale_vertex_igraph(1, par.usr, minmax.relative.size, adjust))
# Adjusting x
xrange <- range(vertex.size)
xscale <- (par.usr[2] - par.usr[1])*minmax.relative.size
vertex.size <- (vertex.size - xrange[1] + 1e-15)/(xrange[2] - xrange[1] + 1e-15)*
(xscale[2] - xscale[1]) + xscale[1]
return(vertex.size*adjust/2)
}
The default in this function will return a vector of length n that can be passed to plot.igraph(...,add=TRUE), resulting on vertices that take sizes between 0.5% and 1% of the plotting region, so if you change the layout (and hence the plotting region) the vertices will have the same size.
The adjust parameter follows a rescaling that igraph does internally when drawing figures via symbols. I would like to include this a patch in igraph but that implies adding extra parameters to the igraph.plotting function and I'm not completely aware of how doing that.
I write this post as a suggestion from Gabor during the useR! 2016 conference.
Working with vertex size is not easy on igraph as that is a function of the plotting region itself. This can be solved by rescaling the vertex size considering the plotting region, further, as done in Gephi, users could provide vertex size and relative scale (minimum/maximum sizes) to the plotting area (e.g. 0.5% and 1.0% of the plotting area). The following code does exactly that:
The default in this function will return a vector of length
nthat can be passed toplot.igraph(...,add=TRUE), resulting on vertices that take sizes between 0.5% and 1% of the plotting region, so if you change the layout (and hence the plotting region) the vertices will have the same size.The
adjustparameter follows a rescaling that igraph does internally when drawing figures viasymbols. I would like to include this a patch in igraph but that implies adding extra parameters to theigraph.plottingfunction and I'm not completely aware of how doing that.I write this post as a suggestion from Gabor during the useR! 2016 conference.