I am creating a network with pie nodes however I have ran into a few issues:
The values I have for the slices of the pie do not match with the image produced
Example:
#generate random slice for my pie charts
valuesq <- lapply(1:23, function(x) sample(0:5,2))
[[1]]
[1] 1 0
[[2]]
[1] 5 1
[[3]]
[1] 1 0
[[4]]
[1] 4 5
[[5]]
[1] 5 3
[[6]]
[1] 1 2
[[7]]
[1] 5 2
[[8]]
[1] 0 2
[[9]]
[1] 0 3
[[10]]
[1] 1 5
[[11]]
[1] 5 3
[[12]]
[1] 5 4
[[13]]
[1] 3 1
[[14]]
[1] 0 3
[[15]]
[1] 4 5
[[16]]
[1] 3 1
[[17]]
[1] 4 1
[[18]]
[1] 4 2
[[19]]
[1] 1 2
[[20]]
[1] 2 4
[[21]]
[1] 1 4
[[22]]
[1] 1 2
[[23]]
[1] 4 1
#plot my chart which has 23 nodes
plot(newig,vertex.shape="pie",vertex.size=20, vertex.pie=valuesq, label.dist=1, label.degree=pi/4)
It produces this plot:
Clearly this is wrong for example node 4(IV) is one solid colour but the vector defining its slices is 4 5
I don't really understand why this is happening any help would be great
A second question I have is how can I match the pie slices to colours e.g. all slices in first column = red and all in second = yellow?
The most probable reason is that the code that assigns the labels to nodes(and is not included) assigns labels to the wrong nodes. Please note that igraph slices the pie in a way that the total area is equal to the sum of all values supplied for that node in the valuesq so for node which is labeled 4 the valuesq[[correctnodenumber]] equals a vector of one number(any number) and a zero. Regarding your second question, the answer is positive. You just need to supply the hexadecimal value (google the word "colorpicker"). I hope the following code and explanation helps.
library(igraph)
newig <- graph.star(n=23,mode="undirected")
valuesq <- lapply(1:23, function(x) c(sample(0:5,2)))
#you can assign up to 5 colors(random colors or exact hex values)
#to 5 slices. Exact hex values could be assigned to all nodes:
V(newig)$pie.color=list(c("#E495A5", "#BDAB66"))
#or to a specific node
V(newig)[10]$pie.color=list(c("#00FF66FF", "#CC00FFFF"))
# let's set a seed number to regenerate the graph so that nodes are
#positioned at the same place every time you run the code.
set.seed(1234)
plot(newig,
vertex.shape="pie",
vertex.size=25,
vertex.pie=valuesq,
vertex.label.dist=0.8,
vertex.label.cex=0.6,
vertex.label.degree=pi,
vertex.label=LETTERS[1:23])
> valuesq
> [[1]] [1] 2 3
>
> [[2]] [1] 1 5
>
> [[3]] [1] 0 1
>
> [[4]] [1] 5 0
>
> [[5]] [1] 1 4
>
> [[6]] [1] 0 2
>
> [[7]] [1] 4 3
>
> [[8]] [1] 1 0
>
> [[9]] [1] 4 5
>
> [[10]] [1] 4 1
>
> [[11]] [1] 5 2
>
> [[12]] [1] 5 3
>
> [[13]] [1] 0 5
>
> [[14]] [1] 5 1
>
> [[15]] [1] 2 3
>
> [[16]] [1] 2 1
>
> [[17]] [1] 3 2
>
> [[18]] [1] 4 0
>
> [[19]] [1] 2 3
>
> [[20]] [1] 3 0
>
> [[21]] [1] 5 4
>
> [[22]] [1] 4 5
>
> [[23]] [1] 3 2