Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9163753
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T14:31:14+00:00 2026-06-17T14:31:14+00:00

I am trying to plot small networks using igraph in R. Each vertex in

  • 0

I am trying to plot small networks using igraph in R. Each vertex in the network has a name, which is equivalent to its label. I would like to make each vertex have a rectangular symbol that is just large enough to fit its label.

This is my main inspiration.

Map of Hyperboria

What is the best way to do this with igraph?

Edit: more information

The code is here

jsonToNM <- function(jfile, directed=TRUE) {
  # Requires "rjson" and "igraph"

  nm.json <- fromJSON(file=jfile)
  nm.graph <- c()

  # Initialize the graph with the given nodes
  g <- graph.empty(n=length(nm.json), directed=directed)
  # Add their names
  V(g)$name <- names(nm.json)
  V(g)$label <- V(g)$name

  # Now, add the edges
  for(i in 1:length(nm.json)) {
    # If the node has a "connected" field,
    # then we note the connections by looking
    # the names up.
    if(length(nm.json[[i]]$connected > 0)) {
      for(j in 1:length(nm.json[[i]]$connected)) {
        # Add the entry
        g <- g + edge(names(nm.json)[i],
                        nm.json[[i]]$connected[j])
      }
    }
  }

  plot(g, vertex.label.dist=1.5)
}

And the current output is below.

current output

My goal is to place the labels inside of the vertex graphic, and expand the width of the vertex to accommodate the label.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T14:31:15+00:00Added an answer on June 17, 2026 at 2:31 pm

    Here is an example. Among some dirty tricks (i.e. multiplying the vertex size by 200), the key is to use two plot commands, so that we can measure the width (and height) of the labels with strwidth(), after the plot size is set with the first (empty) plot.

    library(igraph)
    camp <- graph.formula(Harry:Steve:Don:Bert - Harry:Steve:Don:Bert,
                          Pam:Brazey:Carol:Pat - Pam:Brazey:Carol:Pat,
                          Holly   - Carol:Pat:Pam:Jennie:Bill,
                          Bill    - Pauline:Michael:Lee:Holly,
                          Pauline - Bill:Jennie:Ann,
                          Jennie  - Holly:Michael:Lee:Ann:Pauline,
                          Michael - Bill:Jennie:Ann:Lee:John,
                          Ann     - Michael:Jennie:Pauline,
                          Lee     - Michael:Bill:Jennie,
                          Gery    - Pat:Steve:Russ:John,
                          Russ    - Steve:Bert:Gery:John,
                          John    - Gery:Russ:Michael)
    
    V(camp)$label <- V(camp)$name
    set.seed(42)   ## to make this reproducable
    co <- layout.auto(camp)
    
    plot(0, type="n", ann=FALSE, axes=FALSE, xlim=extendrange(co[,1]), 
         ylim=extendrange(co[,2]))
    plot(camp, layout=co, rescale=FALSE, add=TRUE,
         vertex.shape="rectangle",
         vertex.size=(strwidth(V(camp)$label) + strwidth("oo")) * 100,
         vertex.size2=strheight("I") * 2 * 100)
    

    igraph vertex label width

    Btw. this does not really work well with SVG graphics, because there is no way to measure the width of the text from R, the SVG device only makes guesses.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create a faceted plot using ggplot and geom_errorbar. However, each different
I am trying to plot a graph using gnuplot. I have six text files.
I am trying to plot some data using pylab scatter function. I'm using pylab.scatter(X,
I am trying to plot using piecewise in one of my problems and I
Trying to plot a ConvexHull Using PlanarGraphPlot from the ComputationalGeometry package, it does not
Hi I am trying to plot this using matplotlib's step function from matplotlib.pyplot import
I'm trying to plot a bar chart in ggplot2 where each factor gets the
I am trying to plot a matrix where each element is in one out
I'm trying to plot heatmap in ggplot2 using csv data following casbon's solution in
I am trying to make a contour plot of the following data using matplotlib

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.