HowTo/InputtingData

From Comparative Phylogenetics in R
Jump to: navigation, search

The commands referenced below are all part of special phylogenetic packages in R, not the basic R install. Be sure that you have installed and loaded the packages containing the commands referenced below before continuing. For example:

  library(ape)

This loads the package ape and its required packages gee, lattice and ade4 into your R session.

How do I input a phylogeny into R?

The package APE can read phylogenies in either Newick or NEXUS format using the read.tree and read.nexus commands, respectively.

  MyTree <- read.tree("MyNewickTreefile.tre")
  MyTree <- read.nexus("MyNexusTreefile.nex")

Either of these commands will create an identical object in R containing your tree. Taxon names should appear without quotes. Note that the NEXUS format supports the use of a translation table for taxon names.

How do I export a phylogeny out of R?

The package APE can export phylogenies in either Newick or Nexus format using the write.tree and write.nexus commands, respectivly.

  write.tree(geospiza$geospiza.tree, file="geospiza.tre"
  write.nexus(geospiza$geospiza.tree, file="geospiza.nex"

How do I input data corresponding to the tips of my phylogeny into R?

First, assemble your data into a tab delimited text file (this can be done, for example, in a simple text editor or in MS Excel)

In what ways can I manipulate phylogenies in R?