2
$\begingroup$

I have an ego network (a network of a person (ego) and his friends). It is drawn with the ego at the center surrounded by the friends. It might be possible that all the friends are connected to each other, in which case one can have a complete graph. Mathematica however draws a complete graph with no focal node. How can I make Mathematica draw a complete graph with a center node in it? How can I remove some connections so that it would still be an ego network but not a complete graph? Thanks.

$\endgroup$
4
$\begingroup$

---------- Update -------------

Now because of your comment I understand your problem better. Then it is basically a one-liner:

RandomGraph[{11, 25}, GraphLayout -> {"StarEmbedding", "Center" -> 2},
  GraphStyle -> "SmallNetwork"]

enter image description here

---------- Older versions -------------

Start from {"BalloonEmbedding", "RootVertex" -> k} or {"RadialEmbedding", "RootVertex" -> k} where k is the root vertex (focus) - see this and this for the references:

g = CompleteGraph[12, 
      GraphLayout -> {"BalloonEmbedding", "RootVertex" -> 3}, 
      GraphStyle -> "SmallNetwork"]

enter image description here

You got 55 edges in this case

el = EdgeList[g]; el // Length
55

Now remove some of them but preserve embeding:

Manipulate[Graph[EdgeList[g][[1 ;; m]], VertexCoordinates -> GraphEmbedding[g], 
  GraphStyle -> "SmallNetwork"], {m, 10, 55, 1}]

enter image description here

$\endgroup$
  • $\begingroup$ Could you please link to the doc page of BalloonEmbedding? :) $\endgroup$ – Dr. belisarius Apr 23 '13 at 23:56
  • $\begingroup$ @belisarius Here. The graph related functionality leaves some to be desired both in documentation and quality though ... $\endgroup$ – Szabolcs Apr 24 '13 at 0:06
  • $\begingroup$ @belisarius I put the link in ;) $\endgroup$ – Vitaliy Kaurov Apr 24 '13 at 0:08
  • $\begingroup$ Pfff and I was doing everything manually. Well, you can never know all the functionality :). $\endgroup$ – Jacob Akkerboom Apr 24 '13 at 0:37
  • $\begingroup$ Thanks Vitaly!You have the things I need...(In your manipulate graph though, my case would be 3 (instead of 1) would be connected to everyone else and its the connections among the friends that would be changing). Thanks a lot! $\endgroup$ – newbie py Apr 24 '13 at 1:05
1
$\begingroup$

Ideally, it would be possible to fix the coordinates of one vertex, and let the layout algorithm take care of the rest. I couldn't figure out how to do this with Graph, but it is possible with GraphPlot:

GraphPlot[CompleteGraph[10], VertexCoordinateRules -> {1 -> {0, 0}}]

enter image description here

$\endgroup$
  • $\begingroup$ Thanks a lot Szabolcs! This gives me lots of options! $\endgroup$ – newbie py Apr 24 '13 at 1:07
1
$\begingroup$
nFriends = 10;
coords = Prepend[#, {0, 0}] &[{Sin@#, 
      Cos@#} & /@ (Range[nFriends]/nFriends*2 Pi)];
CompleteGraph[nFriends+1, VertexCoordinates -> coords]

Will give you the complete graph with a vertex in the center.

func = Function[xxxx, UndirectedEdge[#, Last[xxxx]] & /@ Most[xxxx]];
connections = Array[Sequence @@ func@Range[0, #] &, nFriends];

Graph[Range[0, nFriends], connections, VertexCoordinates -> coords]

will give you the same thing, but now the connections are given in the variable connections so that you can now edit them. You can then do

connections = DeleteCases[connections, 
UndirectedEdge[int1, int2]]

to delete the connection between friend int1 and friend int2 (which have to satisfy int1 < int2). Note that the ego is numbered 0 and he is at the center at position {0,0}.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.