how to specify the labels of vertices in R

I have an matrix as below:

          jerry    peter    king
 jerry     1       0        0    
 peter     0       1        0    
 king      1       1        1              

Now I am trying to draw a graph standing for the matrix with the code below:

t <- read.table("../data/table.dat");
adjm <- data.matrix(t);
g1 <- graph.adjacency(adjm,add.colnames=NULL);
plot(g1, main="social network", vertex.color="white", edge.color="grey", vertex.size=8,

The labels of the vertices is the id, so my question is how do I set the label of the vertices by the dimnames of the matrix?

I have tried to the code


but get the wrong graph.


There are 2 ways to do this:

  1. When you create the graph object, assign the names to a vertex attribute called label. This is the default that plot.igraph() looks for when plotting.

    g1 <- graph.adjacency(adjm,add.colnames='label')
  2. Use the V iterator to extract the name vertex attribute, which is how they are stored if you use add.colnames=NULL.

    plot(g1, main="social network", vertex.color="white", edge.color="grey", vertex.size=8, vertex.frame.color="yellow", vertex.label=V(g1)$name)

Either way will give you your desired result. Something like:

Need Your Help

Generating unique keys using RandomStringUtils of apache commons

java java-ee apache-commons hashcode

Please find the below code which I've used to generate random strings using RandomStringUtils of apache commons.

Compute logarithm ln(x) using FPU assembly

visual-studio-2010 assembly masm masm32 fpu

I have a problem with simple logarithm computation using FPU. I am using MASM compiler integrated with Visual Studio 2012.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.