I want to make a tree/flowchart of following data which is properly indented with tabs:
Vertebrates
fish
goldfish
clownfish
amphibian
frog
toad
reptiles
snake
lizard
turtle
tortoise
birds
sparrow
crow
parrot
mammals
dog
cat
horse
whale
How can I convert this tree data to a flowchart (with arrows going from above downwards or from left to right) (proper position to be determined by counting the number of tabs in each row). I believe it can be done with "diagram" package (Graph flow chart of transition from states , http://cran.r-project.org/web/packages/diagram/index.html) but could not figure out exact steps. Thanks for your help.
A rough sample desired output is given below. There could be boxes around text.
EDIT: It should ideally be a flexible solution so that it works if levels are added or removed. For example adding 2 types of sparrows:
Vertebrates
fish
goldfish
clownfish
amphibian
frog
toad
reptiles
snake
lizard
turtle
tortoise
birds
sparrow
house
factory
crow
parrot
crane
mammals
dog
cat
horse
whale
dat = structure(list(V1 = c("Vertebrates", NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA), V2 = c(NA, "fish", NA, NA, "amphibian", NA, NA, "reptiles",
NA, NA, NA, NA, "birds", NA, NA, NA, NA, NA, NA, "mammals", NA,
NA, NA, NA), V3 = c(NA, NA, "goldfish", "clownfish", NA, "frog",
"toad", NA, "snake", "lizard", "turtle", "tortoise", NA, "sparrow",
NA, NA, "crow", "parrot", "crane", NA, "dog", "cat", "horse",
"whale"), V4 = c(NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, "house", "factory", NA, NA, NA, NA, NA, NA, NA, NA
)), .Names = c("V1", "V2", "V3", "V4"), class = "data.frame", row.names = c(NA,
-24L))
>