Order of treechart entries not correct in R igraph package -


This is a follow-up question:

I am using the following function:

  treechart = function () {library (psycho) field & lt; - max (count.fields (readclipboard ()), sep = "\ t") dat = read.table (text = readClipboard (), Sep = "\ t", col.names = paste0 ("V ", Sequence (field)), header = FALSE, fill = true, strip.white = TRUE, stringsAsFactors = FALSE, na.strings =" ") Library (zoo library) (igraph) # to generate data # if less Level (on the right) # is unavailable [1] & lt; - na.locf (for data [1]], Na.rm = FALSE (i ncol (dat): 2) {dat [[i-1]] & lt; - ifelse (! Is.na (dat [[i]]), na.locf (Dat [[i-1]], na.rm = F, dat [[i-1]])} # graph edges Get edges for & lt; - rbind (na.omit (dat [1: 2]), two .call ('rbind', lapply (1: (ncol (dat) -2), function (i) na.omit (setNames (dat [(1 + I): (2 + i)], name (dat [1: 2])))))) # graph graph create & lt; - graph.data.frame (edges) # Plot graph e (g) $ curvature & lt; - 0 plot.igraph (g, top size = 0, edge. Arrow.size = 0, layout = -layout.reingold.tilford (g) [, 2: 1])}   

I am using the following example data (by a separate text editor or tab in a spreadsheet) that I copy with selection and copy- C:

  AAA BBB CCC DDD III JJJ After running the command 'tchchchart ()', I get the following chart:  the image here Enter the description   

Here DDD and EEE BBBb is more than CCC. Similarly, J JJ is coming before 3. How can I correct the function treechart () of this order? Thanks for your help.

It's not that the layout is wrong, it's just that you have layout.reingold Tilford layout and this is what you have got as you can see, it likes to move more complex branches on one side. It does not consider the order that was specified in the corner. I tried to write a new layout function which preserves order

  layout.tree.order & lt; - Function (g, vseq = V (g) $ name, root = vseq [1]) {leaves and lieutenant; - vseq [sapply (vi) [vseq], function (x) length (unique (neighboring (g, x, mode = "out")))) == 0] ypos & lt; - rep (NA, Vcount (g)) ypos [match (leaves, v (g) $ name)]  code>  

Then you can add only one additional row and

  vseq & lt ; - Applicable (data, 1, function (x) na.omit (rev (x)) [1]) plot.igraph (g, vertex.size = 0, edge.arrow.size = 0, layout = layout. Order (g, Vseq))   

Then it is the vseq which specifies the top-down sequence. Here we use the values ​​that they have in your < Code> dat The following conspiracy will be produced from the

Enter image details here

Comments

Popular posts from this blog

ios - Adding an SKSpriteNode to SKScene from a child SKSpriteNode -

Matlab transpose a table vector -

c# - Textbox not clickable but editable -