igraph-help
[Top][All Lists]

## Re: [igraph] creating a graph from special piece of data

 From: Gábor Csárdi Subject: Re: [igraph] creating a graph from special piece of data Date: Fri, 24 Aug 2012 14:26:58 -0400

```Hi,

in reality you have a bipartite (or two-mode) network, because you
have two vertex types: actors and projects, and connections are
possible only between actors and projects.

So you can create a two-mode network first, and then project it into
two one-mode networks: the network of projects and the network of
actors. You are interested in the latter, where two actors are
connected if they have at least one common project.

"Actor,Project,Type,Country
Bremen University,B6,University,Germany
Tokyo University,A1,University,Japan
Schulze GmbH,B2,Company,Germany
School authority London,B6,Authority,England
Meier AG,A1,Company,Austria
Meier AG,P7,Company,Austria
Athens University,K6,University,Greece
"))

## First collect the vertices and the vertex attributes
vertices1 <- tab[,c(1,3,4)]
vertices1 <- vertices1[!duplicated(vertices1[,1]),]

vertices2 <- data.frame(Actor=tab[,2], Type=NA, Country=NA)
vertices2 <- vertices2[!duplicated(vertices2[,1]),]

vertices <- rbind(vertices1, vertices2)

## The edges are simply defined by the first two columns
edges <- tab[,c(1,2)]

G <- graph.data.frame(edges, vertices=vertices, directed=FALSE)

## To make this an igraph bipartite graph, it needs a 'type' vertex attribute
V(G)\$type <- V(G)\$name %in% tab\$Project

## This looks good
str(G, v=T, e=T)

## Create the projection
proj <- bipartite.projection(G)[[1]]

## The network of actors
str(proj, v=T, e=T)

Best,
Gabor

On Fri, Aug 24, 2012 at 7:49 AM, Dominik Santner (CRIE)
> Hello,
>
> I just started working with igraph in R, so I'm a kind of newbie. Maybe my
> problem is easy to solve, but I don't know how.
>
> I want to create a graph from a piece of data. I just found on the internet
> information on how to create graphs from edge lists or adjacency matrices
> and how to add the attribute information from a separated list.
> Unfortunately my data are different. A simplified fictitious example is
> shown here:
>
> Actor        Project    Type        Country
> Miller Inc.        A1    Company        Canada
> Bremen University    B6    University    Germany
> Tokyo University    A1    University    Japan
> Schulze GmbH        B2    Company        Germany
> Miller Inc.        B2    Company        Canada
> School authority London    B6    Authority    England
> Meier AG        A1    Company        Austria
> Meier AG        P7    Company        Austria
> Athens University    K6    University    Greece
>
>
> I want to receive a graph with edges indicating that actors work together in
> the same project (e.g. Miller Inc. and Tokyo University working together in
> project A1). Some actors are listed repeatedly (Miller Inc.) and some
> projects are run by only one actor (P7 by Meier AG). Some actors don't have
> any project partners at all (Athens University). Attribute data (type,
> country) are already included in this data frame.
>
> How can I get an igraph graph from this kind of data including edge
> information and attribute data?
>
> Thanks a lot in advance!
> Dominik
>
> _______________________________________________
> igraph-help mailing list