0

Really confused about what input I should be using, I can't work it out from the example data set.

I have a data set like this:

node1   node2   edge_score
x1      x2      0.1
x1      x3      0.2
x8      x4      0.1
x4      x5      0.4
x6      x7      0.5

(In real life, the score is an indication of how similar two nodes are).

I want to plot these in one of these circle packing graphs.

But I can't work out how to input my data (because I guess here I can two vertices, node A and node B?) compared to the flare data set that they use as an example.

So the input should be the table above and the output should be a bubble plot (one giant circle) with three smaller sub-circles:

One circle has x1, x2 and x3
one circle has x8, x4 and x5
one circle has x6 and x7

if it was possible incorporate the edge score into the size of the circles that would be great but I don't see how edges are included in this analysis, but then, they are read into the example? Or I guess even if someone could demonstrate how to change the node size generally if I added another column with some node size or something.

Konrad Rudolph
  • 530,221
  • 131
  • 937
  • 1,214
Slowat_Kela
  • 1,377
  • 2
  • 22
  • 60

1 Answers1

2

The documentation for ggraph indicates that the "circlepacking" is basically a treemap, so the graph should reflect a hierarchy.

Your graph, as defined, produces three unconnected groups:

library(tidyverse)
library(igraph)
library(ggraph)

df <- read.table(text="node1   node2   edge_score
x1      x2      0.1
x1      x3      0.2
x8      x4      0.1
x4      x5      0.4
x6      x7      0.5", header = TRUE, stringsAsFactors = FALSE)


g <- graph_from_data_frame(
  df,
  directed = TRUE
)

ggraph(g, layout = "auto") +
  geom_edge_link() +
  geom_node_text(aes(label = name)) +
  coord_fixed()

three unconnected groups

If I modify this a bit, I try to get closer to the plot you asked (not exactly by close):

df <- read.table(text="node1   node2   edge_score
x1      x2      0.1
x1      x3      0.2
x2      x6      0.1
x2      x7      0.3
x3      x4      0.1
x4      x5      0.4
x4      x8      0.5", header = TRUE, stringsAsFactors = FALSE)

g <- graph_from_data_frame(
  df,
  directed = TRUE
)

g <- graph_from_data_frame(
  df,
  directed = TRUE
)

V(g)$r = 1

ggraph(g, layout = "auto") +
  geom_edge_link() +
  geom_node_text(aes(label = name)) +
  coord_fixed()

ggraph(g, layout = "circlepack") +
  geom_edge_link() +
  geom_node_circle() +
  geom_node_text(aes(label = name)) +
  coord_fixed()

The graph is more "tree-like"

new graph

And it "circlepacks" a bit better

circlepacked graph

HTH

jmcastagnetto
  • 441
  • 2
  • 7