Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

User-friendly vertex size #161

Open
gvegayon opened this issue Jul 5, 2016 · 0 comments
Open

User-friendly vertex size #161

gvegayon opened this issue Jul 5, 2016 · 0 comments
Labels
wishlist Feature request that has not been chosen for implementation yet; vote or comment to prioritize it!
Milestone

Comments

@gvegayon
Copy link

gvegayon commented Jul 5, 2016

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.

@ntamas ntamas added the wishlist Feature request that has not been chosen for implementation yet; vote or comment to prioritize it! label Nov 2, 2022
@krlmlr krlmlr added this to the future milestone Feb 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wishlist Feature request that has not been chosen for implementation yet; vote or comment to prioritize it!
Projects
None yet
Development

No branches or pull requests

3 participants