1

I did post this last week, but I didn't explain it properly, I hope that some of you can help me this time...

I am trying to draw multilayer concentric rings as vertex of a graph.

Here you can find a simple version of what I did, and here what what I want to do. Note that the edge should also be dragged with the vertex.

This is the code for the former:

library(igraph)
g=graph.empty(4)
g[1,2]=T
g[3,4]=T
resColors=matrix(as.character(list("green","red","green","green","green","grey","grey",  "green","green","green","red","red","green","green","green","green","red","red","green","green")), nrow=vcount(g))
colors = list()
values = list()
for (i in 1:vcount(g)) {
   values[[i]] = rep(1, times = ncol(resColors))
   colors[i] = list(resColors[i,])
}
size=c(60,50,30,20)
plot(g, vertex.shape = "pie", vertex.pie = values, vertex.pie.color = colors, vertex.size = size)

Thanks, Nat

user31168
  • 165
  • 1
  • 5
  • I am not sure what you want, but this code creates overlapping concentric pie charts: `layout(matrix(c(1,1,1,1,2,1,1,1,1), nrow=3)); pie(x=c(0.5,0.3,0.2)); pie(x=c(0.4,0.25,0.35))` – Mark Miller Sep 17 '13 at 04:13
  • This code creates four pie charts, two of which are concentric. However, I am not sure how to add in the arrows: `par(mar=c(1,1,1,1)); layout(matrix(c(1,1,1,0,0,0, 1,2,1,0,0,0, 1,1,1,0,3,0, 0,0,0,0,0,0, 0,0,0,0,0,0, 0,0,0,0,4,0), nrow=6, byrow=TRUE)); pie(x=c(0.4,0.3,0.2,0.1)); pie(x=c(0.4,0.3,0.2,0.1)); pie(x=c(0.4,0.3,0.2,0.1)); pie(x=c(0.4,0.3,0.2,0.1));` – Mark Miller Sep 17 '13 at 04:40
  • Also, take a look at the following page in the igraph docs: http://igraph.sourceforge.net/doc/R/igraph.vertex.shapes.html . It essentially tells you how to create custom vertex shapes for igraph. Chances are that you have to create a custom pie chart drawer function and then pass that to `add.vertex.shape` somehow. – Tamás Sep 17 '13 at 12:47

2 Answers2

0

This might get you started in base R. You would need to play around with the layout and arrows more if you want the arrows to touch the pie charts.

par(mar=c(1,1,1,1)); 
layout(matrix(c(0,0,0,0,0,0,0,
                0,0,0,0,0,0,0,
                1,1,1,1,6,6,0, 
                1,2,2,5,5,6,0, 
                1,2,2,1,0,0,0, 
                1,1,1,3,0,0,0, 
                0,0,0,0,3,0,0, 
                0,0,0,0,0,3,4, 
                0,0,0,0,0,4,4), nrow=9, byrow=TRUE)); 

pie(x=c(0.4,0.3,0.2,0.1), labels = NA); 
pie(x=c(0.4,0.3,0.2,0.1), labels = NA); 

plot(x=1, y=1, type='n', axes = FALSE, xlim = c(0,100), ylim = c(0,100))
arrows(x0=0, y0=100, x1 = 80, y1 = 20, length=0.25)

pie(x=c(0.4,0.3,0.2,0.1), labels = NA); 

plot(x=1, y=1, type='n', axes = FALSE, xlim = c(0,100), ylim = c(0,100))
arrows(x0=0, y0=0, x1 = 80, y1 = 90)

pie(x=c(0.4,0.3,0.2,0.1), labels = NA);

enter image description here

Alternatively, maybe there is a way to mix and match plots and images from different packages that can help in this case. See here: Combine base and ggplot graphics in R figure window

EDIT:

If you just use one plot statement, instead of two in the example above, and fill the entire layout with that one invisible plot, then you could add as many arrows as you want. Importantly, you probably would have very fine-scale control over the placement of those arrows via the x and y coordinates you give to each arrow. You would add the pie charts over the one plot and could probably get the arrows to touch the pie charts with little trouble via trial and error.

Community
  • 1
  • 1
Mark Miller
  • 12,483
  • 23
  • 78
  • 132
0

The solution was simpler than I though, in case someone else needs the answer:

Before plotting, you call a layout, fruchterman.reingold as an example:

lay <- layout.fruchterman.reingold(g)

Then you edit lay, in the example, you want node 3 on node 1:

lay[3,] <- lay[1,]

And finally you plot with the edited layout:

plot(g, vertex.shape = "pie", vertex.pie = values, vertex.pie.color = colors, 
     vertex.size = size, layout = lay)
user31168
  • 165
  • 1
  • 5