0

I am trying to plot a decision tree with igraph. However, I do not know how to create a data structure that will allow to plot a decision tree with igraph.

Any tips?

juanjedi
  • 140
  • 1
  • 7
  • 1
    Please add more information about the problem: have you tried writing any code? How is your data structured (maybe post it using the `dput` and/or `structure` functions)... Check https://stackoverflow.com/help/how-to-ask for more tips – Ricardo Semião e Castro Oct 24 '20 at 19:31
  • It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. – MrFlick Oct 24 '20 at 21:28
  • This may help : https://cran.r-project.org/web/packages/data.tree/vignettes/data.tree.html#plotting – Tou Mou Oct 24 '20 at 22:40

1 Answers1

0

This an example :

library(data.tree)
library(igraph)

acme <- Node$new("Acme Inc.")
  accounting <- acme$AddChild("Accounting")
    software <- accounting$AddChild("New Software")
    standards <- accounting$AddChild("New Accounting Standards")
  research <- acme$AddChild("Research")
    newProductLine <- research$AddChild("New Product Line")
    newLabs <- research$AddChild("New Labs")
  it <- acme$AddChild("IT")
    outsource <- it$AddChild("Outsource")
    agile <- it$AddChild("Go agile")
    goToR <- it$AddChild("Switch to R")

print(acme)
plot(as.igraph(acme, directed = TRUE, direction = "climb"))

Source : https://cran.r-project.org/web/packages/data.tree/vignettes/data.tree.html

Tou Mou
  • 1,270
  • 5
  • 16