This is a test version of Biostars. For the public version, visit https://www.biostars.org.
How to plot phylogenetic tree using R packages

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

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

And what the error message says?

1 answer

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)

Thank you for your help. It works.

Log in to answer this question.