Hi Charles,

I’m sorry... I don’t have a solution to your plotting issues, but here are
a couple of ideas. I know there are two ggplot2 extension packages that
plot or wrangle node based graphs: ggraph and tidygraph. Both were written
by the same developer. ggraph plots relational or network data in a ton of
different shapes, including dendrograms. Tidygraph has some kind of
“join_node()” function to connect the nodes of two separate graphs. It
probably makes it easy to sort or order your network nodes as well. I am
sure there is a way to connect or align your tree tips and food web nodes
in a flexible and aesthetically pleasing way using these tools, but it may
take some work. The dev might be willing help you with that!

Not sure if it’s immediately possible, but maybe you could use the amazing
ggtree package to plot the tree and then connect it to or align it with a
network graph from ggraph?

Good luck!
Jon



On Thu, May 7, 2020 at 5:03 AM <r-sig-phylo-requ...@r-project.org> wrote:

> Send R-sig-phylo mailing list submissions to
>         r-sig-phylo@r-project.org
>
> To subscribe or unsubscribe via the World Wide Web, visit
>         https://stat.ethz.ch/mailman/listinfo/r-sig-phylo
> or, via email, send a message with subject or body 'help' to
>         r-sig-phylo-requ...@r-project.org
>
> You can reach the person managing the list at
>         r-sig-phylo-ow...@r-project.org
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of R-sig-phylo digest..."
>
>
> Today's Topics:
>
>    1. Combining foodwebs and phylogenetic trees (Charles Lehnen)
>
> ----------------------------------------------------------------------
>
> Message: 1
> Date: Tue, 5 May 2020 20:52:48 -0500
> From: Charles Lehnen <charlesleh...@gmail.com>
> To: r-sig-phylo@r-project.org
> Subject: [R-sig-phylo] Combining foodwebs and phylogenetic trees
> Message-ID:
>         <
> caa560r6tehdgg5ffcdcwe3sgudrq2hvkkwnjz1eszmmpd+r...@mail.gmail.com>
> Content-Type: text/plain; charset="utf-8"
>
> I have trying to combine foodweb outputs like the bipartite package's
> plotweb() function of bipartiteD3’s bipartite_D3 function with phylogenetic
> trees, similar to a tanglegram. Because of the very large size and a high
> amount of variability in my dataset, standard tanglegrams turn out very
> convoluted, but the plotweb() outputs are still lovely.
>
> I was able to export tips to manually order the tips of the plotweb()
> output to match the order of the phylogenetic tree tips which allowed me to
> align tips manually in Inkscape, but this proved extremely time consuming
> whenever I made an addition to my dataset.
>
> require('ape')
>
> tree1<-read.tree(text="((A,(B,(C,D))),E);")
> tree1<-ladderize(tree1, right = FALSE)
>
> tree2<-read.tree(text="(F,(G,((H,I),(J,K))));")
>
> is_tip <- tree1$edge[,2] <= length(tree1$tip.label)
> ordered_tips <- tree1$edge[is_tip, 2]
> tree1tips<-tree1$tip.label[ordered_tips]
>
> is_tip <- tree2$edge[,2] <= length(tree2$tip.label)
> ordered_tips <- tree2$edge[is_tip, 2]
> tree2tips<-tree2$tip.label[ordered_tips]
>
>
> I tried to edit the plotweb() script to accept phylo class variables as an
> additional argument, but that was evidently beyond my abilities at this
> time.
>
> I also tried combing the outputs using the grid package, we were able to
> visually combine outputs next to one another and match the order of the
> tips. However, I have not been able to figure out how to actually line up
> the tips of the trees to the outputs of plotweb(). This becomes very
> evident with my actual, very large dataset
>
> require('ape')
> require('bipartite')
> require('ggplotify')
> require('cowplot')
> require('grid')
>
> tree1<-read.tree(text="((A,(B,(C,D))),E);")
> tree1<-ladderize(tree1, right = FALSE)
>
> tree2<-read.tree(text="(F,(G,((H,I),(J,K))));")
>
>
> bipartite<-cbind(c(0,2,3,2,0,0),c(2,0,2,4,8,0),c(4,3,0,0,5,0),c(0,2,0,0,0,1),c(0,7,2,2,0,0))
> colnames(bipartite)<-c("D","C","B","A","E")
> rownames(bipartite)<-c("K","J","I","H","G","F")
> bipartite<-as.data.frame(bipartite)
>
> p12 = as.grob(~cophyloplot(tree1, tree2))
> bipartite = as.data.frame(t(bipartite))
> p3 = as.grob(~plotweb(bipartite,
>         method = "normal",
>         empty = "false",
>         text.rot = "90"
>         ))
> grid.newpage()
> grid.draw(p12)
> vp = viewport(x = 0.53, y = 0.6, width = 0.6, height = 0.8, angle = -90)
> pushViewport(vp)
> grid.draw(p3)
>
>
> If anyone could direct me on how to proceed, I would greatly appreciate it!
> I have been coming back to this problem for many months now and have not
> been to solve it
>
>         [[alternative HTML version deleted]]
>
>
>
>
> ------------------------------
>
> Subject: Digest Footer
>
> _______________________________________________
> R-sig-phylo mailing list
> R-sig-phylo@r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-phylo
>
>
> ------------------------------
>
> End of R-sig-phylo Digest, Vol 148, Issue 1
> *******************************************

-- 
Jonathan A. Nations
PhD Candidate
Esselstyn Lab <https://esselstyn.github.io/>
Museum of Natural Sciences <https://www.lsu.edu/mns/>
Louisiana State University
jonnynations.com

        [[alternative HTML version deleted]]

_______________________________________________
R-sig-phylo mailing list - R-sig-phylo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-phylo
Searchable archive at http://www.mail-archive.com/r-sig-phylo@r-project.org/

Reply via email to