2

I am trying to visualize a network using ggraph. My code is as follows:

ggraph(x, layout = "fr") +
  geom_edge_link(aes(width = weight), alpha = 0.50, edge_color = "grey20") +
  geom_node_point(color = "black", size = 12, show.legend = FALSE, family = "serif") +
  geom_node_label(aes(label = name),  
                  repel = TRUE, show.legend = FALSE, family = "serif") +
  theme_graph(background = "white")

It results in the following snippet of network plot:

Node Image

Is it possible to create labels inside the nodes in ggraph? I tried geom_node_label and geom_node_text but none of them works that way. I also upload an example of what I have in mind below:

Example Image

I would really appreciate your help. I wish everyone a healthy summer.

1 Answers1

0

geom_node_text() is correct. the text was hidden as it was black on black.

x <- data.frame('from' = c(1,2,3,4), 'to' = c(3,3,1,1), 'weight' = c(1,1,1,1))

ggraph(x, layout = "fr") +
  geom_edge_link(aes(width = weight), alpha = 0.50, edge_color = "grey20") +
  geom_node_point(color = "black", size = 12, show.legend = FALSE, family = "serif") +
  geom_node_text(aes(label = name),  colour = 'white', size=10,
                  show.legend = FALSE, family = "serif") +
  theme_graph(background = "white")

gives this plot

enter image description here

Anonymous
  • 183
  • 1
  • 9