I would like to know if there's any way to use the parameter -vertex.size- in -plot.igraph- as it is used in -graphics::symbols- when the last one is called with inches=FALSE, this is symbols(..., inches=TRUE) so that the size of the figure is given by the x-axis.
I'm using -plot.igraph- with add=TRUE and it'l be nice if one could specify -vertex.size- relative to the x-axis. I found a way of doing it but I'm not very comfortable with it. Here goes an example of what I'm doing right now:
rm(list=ls())
library(igraph)
# Random graph and coordinates
set.seed(2134)
g <- barabasi.game(10)
coords <- layout_nicely(g)
size <- runif(10)
size <- cbind(size, size)
shap <- sample(c("circle", "square"),10,TRUE)
# This function rescales a vertex size before passing it to -plot.igraph-
igraph_vs <- function(
vs, # Size of the vertex
par_usr=par("usr"), # Coordinates of the plot region
relative=c(.01,.05), # Relative size of the smallest and largest vertex to x
adjust=200 # Adjustment in igraph
) {
# Adjusting x
xrange <- range(vs[,1])
xscale <- (par_usr[4] - par_usr[3])*relative
vs <- (vs - xrange[1] + 1e-15)/(xrange[2] - xrange[1] + 1e-15)*
(xscale[2] - xscale[1]) + xscale[1]
return(vs*adjust)
}
oldpar <- par(no.readonly = TRUE)
par(mfrow=c(2,2), mai=rep(.5,4))
for (i in seq(1, 1000, length.out = 4)) {
# New plot-window
plot.new()
plot.window(xlim=range(coords[,1]*i), ylim=range(coords[,2]*i))
# plotting graph
plot(g, layout=coords*i, add=TRUE, rescale=FALSE,
vertex.shape = shap,
vertex.size = igraph_vs(size))
# Adding some axis
axis(1, lwd=0, lwd.ticks = 1)
axis(2, lwd=0, lwd.ticks = 1)
box()
}
par(oldpar)
If you run the code you'll see 4 plots of the same graph with same relative layout. The only difference between each plot is on the limits. The function -igraph_vs- resizes the vertex.size before passing it to plot.igraph so that the resulting output all vertices have the same relative size across plots. In other words, all plots look the same but have different xy-ranges.
Again, while this works I was thinking that perhaps there's an easier way to do this (maybe passing some other parameters to -plot.igraph- that I'm not aware of?). Any feedback will be much appreciated.