Arno
Arno

Reputation: 75

Creating a slicing tree in R

Does anyone know if there is a package or simple way in R to create tree structures of the following form:

enter image description here

I am not looking for a way to create a nice plot like above. My biggest problem is finding a way to work with such a tree where there is a clear distinction between nodes, leaves and children-nodes. For example I would like to be able to switch two leaves by adjusting a string or vector. So I guess this is mostly a 'data storage' problem.

I have been looking for quite some time now and stumbled upon a package called 'Dendrogram'. The problem with this package is that (as far as I know) it does not allow the labelling of inner nodes such as 'H'and 'V'. Only the final leaves can carry a value or string.

Another package I found is 'rpart' but I think these are only useful for regression trees.

If anyone knows something I would greatly appreciate the help!

Upvotes: 2

Views: 305

Answers (2)

Simon O'Hanlon
Simon O'Hanlon

Reputation: 59990

If you have an edgelist you can do something very simillar with with igraph:

el <- matrix( c( "H" , "V" , "H" , "V2" , "V" , "1" , "V" , "V3" , "V3" , "3" , "V3" , "4" , "V2" , "2" , "V2" , "H2" ) , ncol = 2 , byrow = TRUE )
g <- graph.edgelist(el , directed = TRUE )
V(g)$label <- get.vertex.attribute(g, 'name')
plot(g,layout=layout.reingold.tilford)

You can also name you nodes in the el command as letters and then use get.vertex.attribute(g, 'name') to see what the resulting nodes are called, and then pass whatever character vector you like to get your labels as they are in the picture. enter image description here

Upvotes: 1

Nishanth
Nishanth

Reputation: 7130

Yes, rpart may not suit your need. Try phylobase package.

If your tree can be read from a file then you could probably use some kind of XML tree parser like this.

Upvotes: 1

Related Questions