# Polar and Ellipsoid Graphs in iGraph in R

Mar 12 2015 Published by under Uncategorized

I'm still working to do some additional graphs for the project mentioned in this earlier post. It was too crowded with the Fruchterman Reingold layout, so my customer suggested we do a circular layout with one category in the center and the remaining on the outer ring. I said sure! But when I went to do it, I found only star layout (one in the center) and ring layout. No polar layout. I tried a few things but finally broke down and asked. Quick perfect answer on StackOverflow (as often happens).

That led to this:

But hey, still pretty jammed up. So what about an ellipse? Sure!

What's that equation again?

$\frac {x^2}{a^2} + \frac {y^2}{b^2} =1$

But that's a hard way to do it when I need x and y values in a matrix. This looks better:

$x = a \cos(\theta) , y=b \sin(\theta)$

And this is how I did it.

ellip.layout <- function(a,b, theta) { cbind(a*cos(theta), -b*sin(theta)) }

systems <- which(V(g)$category == "System") comp <- which(V(g)$category != "System")

a<- ifelse(V(g)$category == "System",4,5) b<- ifelse(V(g)$category == "System",0.5,1)

theta <- rep.int(0, vcount(g)) #creates a blank vector
theta[systems] <- (1:length(systems)-1) * 2 * pi / length(systems)
theta[comp] <- (1:length(comp)-1) * 2 * pi / length(comp)

layout<- ellip.layout(a,b,theta)

plot.igraph(g, layout=layout, asp=0)

Originally I was getting the outer ring to be a circle anyway, but then I asked the mailing list and it was a matter of setting asp (aspect ratio) to 0.

Here's where I ended up:

ETA: If you do labels, there's a neat trick to make them always outside the circle. See here: https://gist.github.com/kjhealy/834774

Tags: ,

Comments are off for this post

•  Support level Reader : $5.00 USD - monthly Supporter :$10.00 USD - monthly Sustainer : $25.00 USD - monthly Angel :$1,200.00 USD - yearly
• Scientopia Blogs

• I'm a science and engineering librarian and information scientist at a university-affiliated research center. I have a BS in Physics, an MLS, and a PhD in Information Studies. Nothing here represents my employer.

• Get updates by email

• ## Contribute to Scientopia

Click here to toss some change in our contribution jar. All funds donated will be used solely to support Scientopia's operating costs. See our Code for more information on our funding policies.
• Where am I?

N 39 W 76

Research Blogging Awards 2010 Finalist

Christina's LIS Rant by Christina K. Pikas is licensed under a Creative Commons Attribution 3.0 Unported License.