How to plot phylogenetic tree using R packages
1
0
Entering edit mode
3.4 years ago
Kumar ▴ 170

Hi, I have aligned result (.nwk) from MEGAX and now looking to visualize the phylogenetic result. I am trying following tutorials. However, I am not sure how to provide my own data in this import command. If I give the command below, I am getting an error. Please suggest how to import my own data to plot the tree.

 ###
 tr = read.tree("/home/mega_alignment/Newick Export.nwk")

####
nwk <- system.file("extdata", "sample.nwk", package="treeio")
tree <- read.tree(nwk)
  1. https://www.molecularecologist.com/2017/02/08/phylogenetic-trees-in-r-using-ggtree/
  2. https://bioconductor.statistik.tu-dortmund.de/packages/3.8/bioc/vignettes/ggtree/inst/doc/treeVisualization.html
ape phylogenetic ggtree • 5.0k views
ADD COMMENT
0
Entering edit mode

If I give the command below, I am getting an error.

And what the error message says?

ADD REPLY
2
Entering edit mode
3.4 years ago
Dunois ★ 2.8k

If you're looking to just plot a tree, all you need are the read.tree() and plot.phylo() function from the ape package. Just copy the path to your tree (if you're on a linux machine, just right click on the file, and click on "Copy"), and supply that as the textual input to read.tree(), and you'd have imported your tree. Save the output of that function to an object, and pass it to plot.phylo(), and you have your tree visualized in R.

Type in ?read.tree and ?plot.phylo to access the respective help documentation.

#install.packages("ape")

library(ape)

mytree <- ape::read.tree("/path/to/tree.nwk")

ape::plot.phylo(mytree)
ADD COMMENT
1
Entering edit mode

Thank you for your help. It works.

ADD REPLY

Login before adding your answer.

Traffic: 2324 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6