Question: plotting phylogenetic trees using R
0
gravatar for sansritisinha
2.6 years ago by
India
sansritisinha0 wrote:

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

phylogenetic tree R • 2.0k views
ADD COMMENTlink written 2.6 years ago by sansritisinha0

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 REPLYlink written 2.6 years ago by ddiez1.8k

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 REPLYlink modified 2.5 years ago by WouterDeCoster40k • written 2.5 years ago by sansritisinha0

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 REPLYlink written 2.5 years ago by ddiez1.8k

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

ADD REPLYlink written 2.5 years ago by sansritisinha0

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 REPLYlink modified 2.5 years ago • written 2.5 years ago by ddiez1.8k

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

ADD REPLYlink written 2.5 years ago by sansritisinha0

Try reading ?write.tree.

ADD REPLYlink written 2.5 years ago by ddiez1.8k
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1693 users visited in the last hour