|
From: | Gábor Csárdi |
Subject: | Re: [igraph] Graphing in a "polar" layout |
Date: | Thu, 12 Mar 2015 11:02:19 -0400 |
The below help worked like a charm and now I've been asked for an ellipse. No problem, I thought to myself, except for some reason my outer ring remains a circle regardless of what I do. Inner ring is fine. Here's what I've done.I hope there's something stupid I forgot, but I just can't find it.
ellip.layout <- function(a,b, theta) {
cbind(a*cos(theta), -b*sin(theta))
}a<- ifelse(males <- which(V(g)$gender == "M") females <- which(V(g)$gender == "F")
V(g)$gender == "M"
,4,5)
b<- ifelse(V(V(g)$gender == "M"
,0.5,1)
theta <- rep.int(0, vcount(g)) #creates a blank vector
theta[males] <- (1:length(males)-1) * 2 * pi / length(males)
theta[females] <- (1:length(females)-1) * 2 * pi / length(females)
layout<- ellip.layout(a,b,theta)
plot.igraph(g, layout=layout)I thought maybe it was squishing it so I tried different values for a and b but that didn't help.
Thank you for your patience!ChristinaOn Thu, Mar 5, 2015 at 12:00 PM, <address@hidden> wrote:
Message: 1
Date: Thu, 5 Mar 2015 12:18:11 +0100
From: Tamas Nepusz <address@hidden>
To: Help for igraph users <address@hidden>
Subject: Re: [igraph] Graphing in a "polar" layout
Message-ID: <address@hidden>
Content-Type: text/plain; charset=us-ascii
Hi Christina,
igraph layouts are simply matrices with 2 columns and one row for each vertex,
so the easiest is probably if you generate such a matrix yourself. If you want
to place a vertex at radius r from the center with an angle of alpha (in
radians), then you have to use the following formulae to figure out the X and
Y coordinates:
X = r * cos(alpha)
Y = -r * sin(alpha)
where the Y coordinate is negated only because the Y axis of the coordinate
system of the screen is oriented from top to bottom.
You haven't mentioned whether you are using igraph from R or Python and I'm
more familar with Python, so I'll add an example in Python here:
from igraph import Layout
from math import sin, cos
def polar_layout(radii, angles):
return Layout([(r*cos(angle), -r*sin(angle)) for r, angle in zip(radii, angles)])
The "polar_layout" function has to be called with two lists: one that specifies
the radius of each vertex and one that specifies the angle of each vertex. It
will then return a Layout object that can be passed to plot() as follows:
layout = polar_layout(..., ...)
plot(graph, layout=layout)
All the best,
Tamas
On 02/04, Christina Pikas wrote:
> I've got ~100 nodes assigned to various categories. I would like to end up
> with nodes of one category in the center and all the other categories
> spaced along a ring outside - like this NodeXL polar graph:
> http://www.connectedaction.net/2013/03/03/how-to-plot-a-network-in-a-polar-layout-using-nodexl/
>
> I know about star layouts (just one node in the center?) and ring or circle
> layouts.
>
> My plan was to find the layout coordinates for subgraphs for each group and
> then copy them all over, but this is proving to be even more of a hassle
> than I had originally thought.
>
> Is there an easier way?
>
> Thanks in advance,
> Christina
> _______________________________________________
> igraph-help mailing list
> address@hidden
> https://lists.nongnu.org/mailman/listinfo/igraph-help
_______________________________________________
igraph-help mailing list
address@hidden
https://lists.nongnu.org/mailman/listinfo/igraph-help
[Prev in Thread] | Current Thread | [Next in Thread] |