igraph-help
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [igraph] error plotting A graph with attributes example


From: Jarrett Byrnes
Subject: Re: [igraph] error plotting A graph with attributes example
Date: Sat, 3 Mar 2007 15:43:39 -0800

After a good deal of fiddling, it appears the problem is having a vertex attribute called "name".  Instead, if you change it to names (and use V(g)$names thereafter) and then in the tkplot statement, use
tkplot(g, layout=layout.kamada.kawai, edge.color=E(g)$color, labels=names(ids))
for short names or
tkplot(g, layout=layout.kamada.kawai, edge.color=E(g)$color, labels=V(g)$names)
for long names, you're all good.

This should be changed in the tutorial.

On Mar 3, 2007, at 1:57 PM, Jarrett Byrnes wrote:


# Read the files first

traits <- read.csv("traits.csv", head=FALSE)

rel <- read.csv("relations.csv", head=FALSE)


# Create the graph, add the vertices

library(igraph)

g <- graph.empty()

g <- add.vertices(g, nrow(traits),

                     name=as.character(traits[,1]), age=traits[,2],

                     gender=as.character(traits[,3]))


# Extract first names from the full names

names <- sapply(strsplit(V(g)$name, " "), "[",1)

ids <- 1:length(names)-1

names(ids) <- names


# Create the edges

from <- as.character(rel[,1])

to <- as.character(rel[,2])

edges <- matrix(c(ids[from], ids[to]), nc=2)


# Add the edges

g <- add.edges(g, t(edges),

               room=as.character(rel[,3]),

      friend=rel[,4], advice=rel[,5])


#plot it

E(g)$color <- "black"

E(g)[ room=="y" ]$color <- "red"

tkplot(g, layout=layout.kamada.kawai, edge.color=E(g)$color)




reply via email to

[Prev in Thread] Current Thread [Next in Thread]