################################################################################ ### R BASICS WORKSHOP ### ### EXERCISE 6.3: Object manipulation, indexing a phylogeny ### ### ### ### Center for Conservation and Sustainable Development ### ### Missouri Botanical Garden ### ### Website: rbasicsworkshop.weebly.com ### ################################################################################ ### INTRODUCTION ############################################## ################## # In this exercise you will explore the structure of objects of class "phylo", # used to represent phylogenies in R. You will manipulate these objects and produce # phylogeny graphs. # TASK 1 ## # Install package "ape" if you haven't already install.packages("ape") # Load "ape" library(ape) ## TASK 2 ## # Read the file "tree_central_ages.new" (available on the workshop page); this file contains # a dated phylogeny (timeline) of all plant families (in "Newick" format). Make sure # to set your working directory to indicate where the "tree_central_ages.new" file is. setwd("C:/_transfer/R_Basics_Workshop/St_Louis_June_2023/DataSets") #Ivan's working directory phylo.fam.world <- read.tree("tree_central_ages.new") ## TASK 3 ## # plot the phylogeny plot(phylo.fam.world, type="fan", cex=0.2) ## TASK 4 ## # Examine the properties of object "phylo.fam.world" class(phylo.fam.world) attributes(phylo.fam.world) str(phylo.fam.world) #note that objects of class "phylo" are lists ## TASK 5 ## # Read the section on objects of class "phylo" on page 30 of Paradis (2012, Analysis # of phylogenetics and evolution with R", available on the workshop page: # http://rbasicsworkshop.weebly.com/books.html). # Use the "$" operator to explore the components of the phylo class: "edge", # "edge.length", "tip.label", "Nnode", "node.lable", "root.edge". For example: phylo.fam.world$edge # note that you can use numeric indexing on each component, for example: phylo.fam.world$edge[1:7,] ## TASK 6 ## # Examine the object classes returned by indexing with single and double square brackets: class(phylo.fam.world[1]) class(phylo.fam.world[[1]]) class(phylo.fam.world[2]) class(phylo.fam.world[[2]]) class(phylo.fam.world[3]) class(phylo.fam.world[[3]]) ## TASK 7 ## # Examine the names of the phylogeny tips phylo.fam.world$tip.label # study the following code, it is used to edit the names of the phylogeny tips, # changing the first letter from lowercase to uppercase; to understand the code, visit the help # pages for functions "paste", "toupper", and "substring": phylo.fam.world$tip.label <- paste(toupper(substring(phylo.fam.world$tip.label, 1, 1)), substring(phylo.fam.world$tip.label, 2), sep= "") #examine the result phylo.fam.world$tip.label ## TASK 8 ## # Study the following code carefully. Visit the help page for function "drop.tip". # Use this function to plot a selection of phylogeny tips, for example: phylo.fam.world.1 <- drop.tip(phylo.fam.world, 25:476, subtree=TRUE) plot(phylo.fam.world.1, type="p", cex=0.8, show.node.label=F) axisPhylo(1) phylo.fam.world.2 <- drop.tip(phylo.fam.world, c(1:24,51:476), subtree=TRUE) plot(as.phylo(phylo.fam.world.2), type="p", cex=0.8,show.node.label=F) axisPhylo(1) phylo.fam.world.3 <- drop.tip(phylo.fam.world, c(1:50,70:476), subtree=TRUE) plot(as.phylo(phylo.fam.world.3), type="p", cex=0.8,show.node.label=F) axisPhylo(1) # Write your own code for other similar cases