plotting phylogenetic trees using R
0
0
Entering edit mode
7.2 years ago

I wanted to remove one of the taxa from the tree. so i downloaded ape package and using drop.tip i could remove the taxa. but I am unable to print/plot the modified tree. i tried using plot() for plotting the tree but it seems to be specified with ylim values. how do i get ylim values for the tree? or is there a different way of plotting the tree?

thank you

R phylogenetic tree • 4.4k views
ADD COMMENT
0
Entering edit mode

Please add the code you used, ideally with a minimum reproducible example (i.e. a small dataset that we can use to reproduce your problem). Also, for plotting trees take a look at the ggtree package and its documentation, for example the introduction.

ADD REPLY
0
Entering edit mode

I used the following:

library (ape)
phylo <-read.tree ("mytree.nwk")
drop.tip (phylo, "taxa_name")

With this the taxa I wanted to remove was removed and the tree now had a taxa less than what it had. I do not know how to display/ rite/plot the modified tree

ADD REPLY
0
Entering edit mode

Take a look at ?drop.tip documentation. There it says the returned value from drop.tip is a phylo object. Therefore, you need to assign the returned value to a variable and plot that.

ADD REPLY
0
Entering edit mode

how do I do that? I am using R for the first time. can you please help me with the code?

ADD REPLY
0
Entering edit mode

OK, something like this:

library(ape)
tree <- read.tree("mytree.nwk") # read tree, assign to variable tree.
plot(tree) # you can plot this.
tree2 <- drop.tip (tree, "taxa_name") # drop taxa, returns a modified tree. we assign it to variable tree2.
plot(tree2) # you can also plot this.

I would highly recommend you to read some introduction to R. There are many in the documentation section at http://www.r-project.org

ADD REPLY
0
Entering edit mode

it worked. thank you so much! Can I export this tree in newick format?

ADD REPLY
0
Entering edit mode

Try reading ?write.tree.

ADD REPLY

Login before adding your answer.

Traffic: 1301 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