I am having some trouble forcing the labels I want in ggraph
. I have a data frame for edges, another one for nodes that look like this:
> edges
# A tibble: 160 × 2
Elec1n Elec2n
<dbl> <dbl>
1 1 45
2 1 44
3 1 42
4 1 41
5 1 34
6 2 50
7 2 49
8 2 40
9 2 39
10 2 35
# … with 150 more rows
> nodes
# A tibble: 52 × 6
group label degrees family order elec
<chr> <fct> <dbl> <fct> <dbl> <dbl>
1 1 Fp1_1 5 fronp 1 1
2 1 Fp2_1 9 fronp 2 2
3 1 F7_1 6 fron 3 3
4 1 F3_1 7 fron 4 4
5 1 Fz_1 11 fron 5 5
6 1 F4_1 9 fron 6 6
7 1 F8_1 11 fron 7 7
8 1 FC5_1 8 fronc 8 8
9 1 FC1_1 6 fronc 9 9
10 1 FC2_1 4 fronc 10 10
# … with 42 more rows
As it can be seen, I reordered because I wanted certain electrodes to be ordered in a certain way, frontal electrodes up, and coming down with the same logic at both sides. There are other intentional dummy variables also to separate both sides. At the end, I will have 25 electrodes connecting to other 25 electrodes in the other side, and using graph and the labels out of the nodes data frame I have the following:
elec <- nodes$label
net.tidy <- tbl_graph(nodes = nodes, edges = edges, directed = TRUE, node_key = "label")
plt <- ggraph(net.tidy, layout = 'linear', circular = TRUE) +
ggtitle("Circular network plot of ") +
geom_edge_arc(aes(color = edge_family),alpha = 0.5) +
scale_edge_colour_manual(values = paletteE) +
scale_edge_width(range = c(0.2, 2)) +
scale_colour_manual(values= palette) +
geom_node_point(aes(size = degrees, color = family)) +
coord_cartesian(clip = "off") +
theme_graph(base_family = 'Helvetica') +
theme(legend.position = "right")
put <- plt +
geom_node_text(aes(label = elec), size = 4, nudge_x = plt$data$x * .15, nudge_y = plt$data$y * .15, check_overlap=FALSE)
plt
This, with other code I am not getting into, gives me the following plot:
My concern here is I don't understand why geom_node_text(aes(label = elec)
is not working and taking the labels to the nodes and it still uses the numeration of the electrodes instead of its names.
Do anybody know why this could be happening? Does anybody know why I can't force the labels into the geom_node_text
?
Thanks in advance.