-11

Is it possible to build a tree which is similar to the following graph? Mainly that tree should express how the number of crew members splits into classes.

df<-data.frame(Titanic)
df_Crew <- df[df$Class=="Crew",]
L <- lapply(1:4, function(i) aggregate(df_Crew$Freq, by=df_Crew[1:i], sum))
L2 <- lapply(L, function(d) data.frame(group=do.call(paste, c(as.list(d[names(d)!="x"]), sep="_")), freq=d$x))
L3<-data.frame()
for(i in 1:3){
    d<-cbind(from=rbind(L2[[i]],L2[[i]])$group,L2[[i+1]])
    L3<-rbind(L3,d)
}
library(igraph)
g <- graph.data.frame(L3, directed=TRUE)
plot(g,layout=layout.reingold.tilford(g,root=1),edge.arrow.size=0.5)
Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
Klaus
  • 1,946
  • 3
  • 19
  • 34
  • Please stop deleting and reposting the same question. I can only assume you do this to erase the comment history and/or bump your question to the top of the queue. Neither is an appropriate use of this website. – Thomas Aug 19 '13 at 07:45
  • 1) No its not the same question. 2) I only delete the post because the corrections and comments destroyed my question, so that people they have answer, cant read it any more after your "corrections". 3) Someone who read the question would think there is a answer in my earlier post. – Klaus Aug 19 '13 at 08:20
  • 5
    You can *roll back* edits to your posts if you don't agree with edits. Do not, however, get into an edit war; you can flag your post for moderator attention a dispute over content arrises. Deleting and reposting is **not** a good idea. – Martijn Pieters Aug 19 '13 at 08:31

1 Answers1

4

You can build it with rpart using your logic for the same

rpart->binary decision tree(CART-->classification and regression tree),make a binary/non binary series for each different node and pass it to rpart().

similarly with others also so read out packages in order to apply logic to convert it into their input format.

Aashu
  • 1,247
  • 1
  • 26
  • 41
  • 1) Many thx for the constructive answer. 2) I give the example, hence some one could show me what are the input for a function like rpart to get a similar result. – Klaus Aug 19 '13 at 09:59
  • @Klaus hope this link http://stackoverflow.com/questions/13545391/formulate-data-for-rpart will help you out. – Aashu Aug 21 '13 at 05:48
  • this one to build http://stackoverflow.com/questions/13011496/splits-and-root-node-of-binary-decision-treecart – Aashu Sep 20 '13 at 07:57