0

suppose i have a variable x which gives the sizes of the pie slices as follows:

x

[[1]]

Celebrity    Corporate 
        2            6 

[[2]]

Celebrity    Government  Unverified 
        2             1           4 

[[3]]

Celebrity    Media   Unverified 
        5        1            6 

My code was here:

plot(my_graph, vertex.shape="pie", vertex.pie=x, vertex.pie.color=???, vertex.label=NA, edge.arrow.mode=0)

My question is how could I specify colors for Celebrity, Media, Corporate, Government, and Unverified manually and plot my_graph using pie charts as vertices.

cxstam
  • 303
  • 1
  • 5
  • 13
  • 1
    First, can you do a `dput()` of your variable? Second, even though you have the `igraph` tag, it would also help to provide a [minimal reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) (i.e. have some code that includes said `dput` and the minimal setup for `library(igraph)`… to the `plot` code) – hrbrmstr Mar 23 '14 at 12:08

1 Answers1

2

Having made said comment above, you can set the individual colors for each vertex with V().

Riffing off the pie igraph example itself:

library(igraph)

g <- graph.ring(10)

values <- lapply(1:10, function(x) c(sample(1:10,3),0,0))

# make some unique bits
values[[7]][5] = 6
values[[9]][4] = 3

# default for all
V(g)$pie.color=list(heat.colors(5))

# make one stand out
V(g)[6]$pie.color=list(topo.colors(5))

# set.seed() keeps the vertices in the same place each plot
set.seed(1492)

plot(g,
     vertex.shape="pie", 
     vertex.pie=values,
     vertex.size=seq(10, 30, length=10), 
     vertex.label=NA)

Please don't do this. Pies are EVIL

It should be straightforward to adapt your needs with that sample.

Community
  • 1
  • 1
hrbrmstr
  • 77,368
  • 11
  • 139
  • 205
  • I also feel compelled to insert the obligatory *"for the love of Henry please don't do this! Pies are evil!"* statement :-) – hrbrmstr Mar 23 '14 at 12:34