1

I have an igraph (R) graph object named g like this:

IGRAPH UNW- 6 5 -- 
+ attr: name (v/c), weight (e/n)
+ edges (vertex names):
[1] 1--4 1--5 1--6 4--2 3--5

I run clustering on it like this:

c1 <-  cluster_fast_greedy(g)

I then convert it to a hclust object like this:

hc <-  as.hclust(c1)

Checking the labels at this point yields:

> hc$labels
[1] "1" "4" "3" "5" "6" "2"

Then using networkD3, I convert that to a radialNetwork

rad <- as.radialNetwork(hc)

I plot it with (for example):

D3graph <- radialNetwork(List = rad, 
                         fontSize = 10, 
                         opacity = 0.8, 
                         margin=1, 
                         fontFamily = "sans-serif",
                         nodeColour = "grey",
                         nodeStroke = "white"
                         )

But a node named hc, and a set of unnamed nodes turn up in the dendrogram. Like this:enter image description here

Simon Lindgren
  • 2,011
  • 12
  • 32
  • 46

1 Answers1

2

You can set the root node name in the as.radialNetwork function to a zero-length string...

library(networkD3)
hc <- hclust(dist(USArrests), "ave")
rad <- as.radialNetwork(hc, '')
radialNetwork(List = rad)

I can't see what your object g is without a minimal reproducible example, so I can't explain why your nodes are not labeled, but I suspect that happens in either your cluster_fast_greedy function or the as.hclust function. hc$labels should show what your labels are set to (or are not set to) before you get to the as.radialNetwork function.

Community
  • 1
  • 1
CJ Yetman
  • 8,373
  • 2
  • 24
  • 56
  • I edited above to show the contents of `g` and added the output of `hc$labels`. Even if specifying root node, I get unnamed 'extra' nodes. – Simon Lindgren May 13 '17 at 14:03
  • `hc$labels` shows you what your labels are set to. They are set to `"1" "4" "3" "5" "6" "2"`. Those are the same labels you see on the `radialNetwork` output. – CJ Yetman May 13 '17 at 14:06
  • But what does the `hc` node and the unnamed nodes on the image represent? – Simon Lindgren May 13 '17 at 14:09
  • `hc` node is the root. unnamed nodes are clusters of your nodes – CJ Yetman May 13 '17 at 14:11
  • Yes, thanks! Now I see. Many online examples of radialNetwork have named cluster nodes. Were they likely manually added? Can I visualise the radialNetwork without clusters? – Simon Lindgren May 13 '17 at 14:16
  • absolutely... see the example on the site http://christophergandrud.github.io/networkD3/#radial – CJ Yetman May 13 '17 at 14:20
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/144131/discussion-between-textnet-and-cj-yetman). – Simon Lindgren May 13 '17 at 14:21
  • btw... if you want to use your igraph object without clustering it first, you should be able to do this `radialNetwork(igraph_to_networkD3(g))` – CJ Yetman May 17 '17 at 13:44