Using pie charts as vertices in graph plots and specify a color for each factor

StackOverflow https://stackoverflow.com/questions/22587959

  •  19-06-2023
  •  | 
  •  

Pergunta

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.

Foi útil?

Solução

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.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top