Recent Changes for "III. Loading Character Data into R" - Bodega Phylogenetics Wikihttp://bodegaphylo.wikispot.org/III._Loading_Character_Data_into_RRecent Changes of the page "III. Loading Character Data into R" on Bodega Phylogenetics Wiki.en-us III. Loading Character Data into Rhttp://bodegaphylo.wikispot.org/III._Loading_Character_Data_into_R2012-04-07 20:01:46(quick edit) <div id="content" class="wikipage content"> Differences for III. Loading Character Data into R<p><strong></strong></p><table> <tr> <td> <span> Deletions are marked with - . </span> </td> <td> <span> Additions are marked with +. </span> </td> </tr> <tr> <td> Line 102: </td> <td> Line 102: </td> </tr> <tr> <td> <span>-</span> Further explanation of the segments command: This command is broken down into <span>three</span> parts: (1) starting X coordinates, (2) starting Y coordinates, (3) ending X coordinates, (4) ending Y coordinates. The first part of this command {{{rep(123,85)}}} uses the {{{rep}}} command to generate a vector that contains the value {{{123}}} repeated 85 times. We're doing this because we want to create a line for each of the 85 taxa in our tree, and we want all of these lines to start at an x-value of {{{123}}} (you may find that you need to adjust this value on a case-by-case basis to make the lines appear where you want them relative to the tips of your tree). The next command {{{1:85}}} tells R that we want lines to begin at integer values ranging from 1-85 on the Y axis: by convention, the tips of phylogentic trees are found at integer values along the Y axis. The next part of this command {{{rep(123,85) + SVL[anolisComparativeTree$tip.label]}}}} tells R how far lines will extend along the X-axis, in this case, they're going to be as long as the SVL value for the species in our dataset. The final part tells R that our segments will be horizontal lines by repeating the vector with integer values ranging from 1 to 85 for the final Y coordinates of each line. </td> <td> <span>+</span> Further explanation of the segments command: This command is broken down into <span>four</span> parts: (1) starting X coordinates, (2) starting Y coordinates, (3) ending X coordinates, (4) ending Y coordinates. The first part of this command {{{rep(123,85)}}} uses the {{{rep}}} command to generate a vector that contains the value {{{123}}} repeated 85 times. We're doing this because we want to create a line for each of the 85 taxa in our tree, and we want all of these lines to start at an x-value of {{{123}}} (you may find that you need to adjust this value on a case-by-case basis to make the lines appear where you want them relative to the tips of your tree). The next command {{{1:85}}} tells R that we want lines to begin at integer values ranging from 1-85 on the Y axis: by convention, the tips of phylogentic trees are found at integer values along the Y axis. The next part of this command {{{rep(123,85) + SVL[anolisComparativeTree$tip.label]}}}} tells R how far lines will extend along the X-axis, in this case, they're going to be as long as the SVL value for the species in our dataset. The final part tells R that our segments will be horizontal lines by repeating the vector with integer values ranging from 1 to 85 for the final Y coordinates of each line. </td> </tr> </table> </div> III. Loading Character Data into Rhttp://bodegaphylo.wikispot.org/III._Loading_Character_Data_into_R2012-03-13 12:42:02(quick edit) <div id="content" class="wikipage content"> Differences for III. Loading Character Data into R<p><strong></strong></p><table> <tr> <td> <span> Deletions are marked with - . </span> </td> <td> <span> Additions are marked with +. </span> </td> </tr> <tr> <td> Line 94: </td> <td> Line 94: </td> </tr> <tr> <td> <span>- </span>NOTE: The {{{points}}} command will only work if you already have a plotting window open. This is because {{{points}}} is trying to add points to an already existing figure. Go back and repeat the plotting function implemented in step 1a if you closed your {{{Quartz}}} window between then and now. </td> <td> <span>+ It is important to realize that microLabel[anolisComparativeTree$tip.label] is crucial as it sorts the microLabel to match the the tip labels on the tree!<br> + <br> + </span>NOTE: The {{{points}}} command will only work if you already have a plotting window open. This is because {{{points}}} is trying to add points to an already existing figure. Go back and repeat the plotting function implemented in step 1a if you closed your {{{Quartz}}} window between then and now. </td> </tr> </table> </div> III. Loading Character Data into Rhttp://bodegaphylo.wikispot.org/III._Loading_Character_Data_into_R2011-12-15 04:41:11(quick edit) <div id="content" class="wikipage content"> Differences for III. Loading Character Data into R<p><strong></strong></p><table> <tr> <td> <span> Deletions are marked with - . </span> </td> <td> <span> Additions are marked with +. </span> </td> </tr> <tr> <td> Line 16: </td> <td> Line 16: </td> </tr> <tr> <td> <span>-</span> I<span>’</span>ve provided you with a comma-delimited table of data called [http://bodegaphylo.wikispot.org/Phylogenetics_and_Comparative_Methods_in_R?action=Files&amp;do=view&amp;target=anolis_data.csv anolis_data.csv]. This file contains ecological and morphological data for Greater Antillean Anolis lizards. This file includes three columns: the first contains species names, the second includes discretely coded information about anole microhabitat specialization (0=grass-bush, 1=trunk-ground, 2=trunk, 3=trunk-crown, 4=crown-giant, 5=twig), and the third contains continuously-coded data on adult body size of adult males (measured as the snout to vent length, or SVL). </td> <td> <span>+</span> I<span>'</span>ve provided you with a comma-delimited table of data called [http://bodegaphylo.wikispot.org/Phylogenetics_and_Comparative_Methods_in_R?action=Files&amp;do=view&amp;target=anolis_data.csv anolis_data.csv]. This file contains ecological and morphological data for Greater Antillean Anolis lizards. This file includes three columns: the first contains species names, the second includes discretely coded information about anole microhabitat specialization (0=grass-bush, 1=trunk-ground, 2=trunk, 3=trunk-crown, 4=crown-giant, 5=twig), and the third contains continuously-coded data on adult body size of adult males (measured as the snout to vent length, or SVL). </td> </tr> </table> </div> III. Loading Character Data into Rhttp://bodegaphylo.wikispot.org/III._Loading_Character_Data_into_R2011-03-08 10:37:54(quick edit) <div id="content" class="wikipage content"> Differences for III. Loading Character Data into R<p><strong></strong></p><table> <tr> <td> <span> Deletions are marked with - . </span> </td> <td> <span> Additions are marked with +. </span> </td> </tr> <tr> <td> Line 88: </td> <td> Line 88: </td> </tr> <tr> <td> <span>-</span> {{{plot(anolisComparativeTree, cex=0.5, off<span>.</span>set=<span>0.4</span>)}}} </td> <td> <span>+</span> {{{plot(anolisComparativeTree, cex=0.5, <span>label.</span>offset=<span>2</span>)}}} </td> </tr> </table> </div> III. Loading Character Data into Rhttp://bodegaphylo.wikispot.org/III._Loading_Character_Data_into_R2011-03-06 16:18:01glor <div id="content" class="wikipage content"> Differences for III. Loading Character Data into R<p><strong></strong></p><table> <tr> <td> <span> Deletions are marked with - . </span> </td> <td> <span> Additions are marked with +. </span> </td> </tr> <tr> <td> Line 92: </td> <td> Line 92: </td> </tr> <tr> <td> <span>-</span> {{{points(rep(10<span>0.5</span>, length(anolisComparativeTree$tip.label)), 1:length(anolisComparativeTree$tip.label), pch=22, bg=microLabel[anolisComparativeTree$tip.label], cex=0.5, lwd=0.25)}}} </td> <td> <span>+</span> {{{points(rep(10<span>4</span>, length(anolisComparativeTree$tip.label)), 1:length(anolisComparativeTree$tip.label), pch=22, bg=microLabel[anolisComparativeTree$tip.label], cex=0.5, lwd=0.25)}}} </td> </tr> </table> </div> III. Loading Character Data into Rhttp://bodegaphylo.wikispot.org/III._Loading_Character_Data_into_R2011-03-06 11:56:14glor <div id="content" class="wikipage content"> Differences for III. Loading Character Data into R<p><strong></strong></p><table> <tr> <td> <span> Deletions are marked with - . </span> </td> <td> <span> Additions are marked with +. </span> </td> </tr> <tr> <td> Line 100: </td> <td> Line 100: </td> </tr> <tr> <td> <span>- </span>Further explanation of the segments command: This command is broken down into three parts: (1) starting X coordinates, (2) starting Y coordinates, (3) ending X coordinates, (4) ending Y coordinates. The first part of this command {{{rep(123,85)}}} uses the {{{rep}}} command to generate a vector that contains the value {{{123}}} repeated 85 times. We're doing this because we want to create a line for each of the 85 taxa in our tree, and we want all of these lines to start at an x-value of {{{123}}} (you may find that you need to adjust this value on a case-by-case basis to make the lines appear where you want them relative to the tips of your tree). The next command {{{1:85}}} tells R that we want lines to begin at integer values ranging from 1-85 on the Y axis: by convention, the tips of phylogentic trees are found at integer values along the Y axis. The next part of this command {{{rep(123,85) + SVL[anolisComparativeTree$tip.label]}}}} tells R how far lines will extend along the X-axis, in this case, they're going to be as long as the SVL value for the species in our dataset. The final part tells R that our segments will be horizontal lines by repeating the vector with integer values ranging from 1 to 85 for the final Y coordinates of each line. </td> <td> <span>+ </span>Further explanation of the segments command: This command is broken down into three parts: (1) starting X coordinates, (2) starting Y coordinates, (3) ending X coordinates, (4) ending Y coordinates. The first part of this command {{{rep(123,85)}}} uses the {{{rep}}} command to generate a vector that contains the value {{{123}}} repeated 85 times. We're doing this because we want to create a line for each of the 85 taxa in our tree, and we want all of these lines to start at an x-value of {{{123}}} (you may find that you need to adjust this value on a case-by-case basis to make the lines appear where you want them relative to the tips of your tree). The next command {{{1:85}}} tells R that we want lines to begin at integer values ranging from 1-85 on the Y axis: by convention, the tips of phylogentic trees are found at integer values along the Y axis. The next part of this command {{{rep(123,85) + SVL[anolisComparativeTree$tip.label]}}}} tells R how far lines will extend along the X-axis, in this case, they're going to be as long as the SVL value for the species in our dataset. The final part tells R that our segments will be horizontal lines by repeating the vector with integer values ranging from 1 to 85 for the final Y coordinates of each line. </td> </tr> </table> </div> III. Loading Character Data into Rhttp://bodegaphylo.wikispot.org/III._Loading_Character_Data_into_R2011-03-06 11:55:34glor <div id="content" class="wikipage content"> Differences for III. Loading Character Data into R<p><strong></strong></p><table> <tr> <td> <span> Deletions are marked with - . </span> </td> <td> <span> Additions are marked with +. </span> </td> </tr> <tr> <td> Line 71: </td> <td> Line 71: </td> </tr> <tr> <td> <span>-</span> '''1.''' We often would like to plot the data for our comparative analysis across the tips of our tree. With a bit of practice, this can be done fairly easily in R.<span>&nbsp;&nbsp;Let’s plot the data for adult male body size on the tips of our tree for anoles.</span> </td> <td> <span>+</span> '''1.''' We often would like to plot the data for our comparative analysis across the tips of our tree. With a bit of practice, this can be done fairly easily in R. </td> </tr> <tr> <td> Line 73: </td> <td> Line 73: </td> </tr> <tr> <td> <span>- '''a.''' We first want to plot a basic tree. Let's try looking at our data on an ultrametric tree. Ordinarily, you'd want import an ultrametric tree into R from a program like BEAST. For simplicity, however, we're just going to look at a tree generated using the non-parametric rate-smoothing function (NPRS) that is implemented internally by R.<br> - <br> - {{{&gt;chronogram(anolisComparativeTree, scale=100) -&gt; anolisChronogram<br> - &gt;plot(anolisChronogram, x.lim=100, show.tip.label=FALSE)}}}<br> - <br> - '''b.''' Now let's add colored boxes to indicate microhabitat specialist states. This may seem a bit complicated at first, but you'll appreciate the flexibility of the method if you stick with it. We're going to start by making a dummy vector that is formatted to store character data. The names of the cells in this dummy vector will correspond with the names of our tip taxa. We're soon going to fill this vector in with the names of the colors we'd like to use for labeling.</span> </td> <td> <span>+ '''a.''' Now let's add colored boxes to indicate microhabitat specialist states. This may seem a bit complicated at first, but you'll appreciate the flexibility of the method if you stick with it. We're going to start by making a dummy vector that is formatted to store character data. The names of the cells in this dummy vector will correspond with the names of our tip taxa. We're soon going to fill this vector in with the names of the colors we'd like to use for labeling.</span> </td> </tr> <tr> <td> Line 91: </td> <td> Line 86: </td> </tr> <tr> <td> <span>-</span> '''<span>c</span>.''' Our next challenge is to plot these colors across the tips of our tree. To do this, we're going to use the {{{points}}} command. This command is used to give the X and Y coordinates of places on our figure where we'd like to place points. We can also specify what types of points we'd like to use with the {{{pch}}} command and what color we'd like these points to be using the previously generated {{{microLabel}}} vector. </td> <td> <span>+</span> '''<span>b</span>.''' Our next challenge is to plot these colors across the tips of our tree. To do this, we're going to use the {{{points}}} command. This command is used to give the X and Y coordinates of places on our figure where we'd like to place points. We can also specify what types of points we'd like to use with the {{{pch}}} command and what color we'd like these points to be using the previously generated {{{microLabel}}} vector.<span>&nbsp;&nbsp;Let's first replot our tree, using the label.offset command to make room for the character data (you can play around with the label offset value to see how higher values move your taxon labels increasingly further away from the tree tips).<br> + <br> + {{{plot(anolisComparativeTree, cex=0.5, off.set=0.4)}}}<br> + <br> + Once the tree is replotted, we're ready to add the points.</span> </td> </tr> <tr> <td> Line 97: </td> <td> Line 96: </td> </tr> <tr> <td> <span>- '''d.''' Now let's add scale bars that indicate the size of each species to this tree. The way we're going to do this is by telling R to make {{{segments}}} at the tips of our tree that scale with body size. The {{{segments}}} command works by connecting points in R's X/Y coordinate space with a line, or segment. We're going to use this command to make a series of lines connecting two points using the following command:</span> </td> <td> <span>+ '''c.''' Now let's add scale bars that indicate the size of each species to this tree. The way we're going to do this is by telling R to make {{{segments}}} at the tips of our tree that scale with body size. To keep things simple, lets just put these segments to the right of the taxon names. The {{{segments}}} command works by connecting points in R's X/Y coordinate space with a line, or segment. We need to tell R where to start a segment on the X/Y axis and where to end this segment along the X/Y axis. The syntax for doing this involves telling R where to start and stop the segment involves (Xstart, Ystart, Xfinish, Yfinish). To make segments after the taxon names, we're going to start at 123 units down the x-axis (a value that we determine from the starting knowledge that our tree is 100 units long combined and subsequently playing around with possible values until we get the segments to appear after the taxon names). From this point, we extend a line whose length corresponds with the lizards body size using the following command:</span> </td> </tr> <tr> <td> Line 99: </td> <td> Line 98: </td> </tr> <tr> <td> <span>-</span> {{{ &gt;segments(rep(1<span>01.5</span>,85), 1:85, rep(1<span>01.5</span>,85) + SVL[anolisComparativeTree$tip.label], 1:85, lwd=2)}}} </td> <td> <span>+</span> {{{ &gt;segments(rep(1<span>23</span>,85), 1:85, rep(1<span>23</span>,85) + SVL[anolisComparativeTree$tip.label], 1:85, lwd=2)}}} </td> </tr> <tr> <td> Line 101: </td> <td> Line 100: </td> </tr> <tr> <td> <span>- </span>This command is broken down into three parts: (1) starting X coordinates, (2) starting Y coordinates, (3) ending X coordinates, (4) ending Y coordinates. The first part of this command {{{rep(1<span>01.5</span>,85)}}} uses the {{{rep}}} command to generate a vector that contains the value {{{1<span>01.5</span>}}} repeated 85 times. We're doing this because we want to create a line for each of the 85 taxa in our tree, and we want all of these lines to start at an x-value of {{{1<span>01.5</span>}}} (you may find that you need to adjust this value on a case-by-case basis to make the lines appear where you want them relative to the tips of your tree). The next command {{{1:85}}} tells R that we want lines to begin at integer values ranging from 1-85 on the Y axis: by convention, the tips of phylogentic trees are found at integer values along the Y axis. The next part of this command {{{rep(1<span>01.5</span>,85) + SVL[anolisComparativeTree$tip.label]}}}} tells R how far lines will extend along the X-axis, in this case, they're going to be as long as the SVL value for the species in our dataset. The final part tells R that our segments will be horizontal lines by repeating the vector with integer values ranging from 1 to 85 for the final Y coordinates of each line. </td> <td> <span>+ Further explanation of the segments command: </span>This command is broken down into three parts: (1) starting X coordinates, (2) starting Y coordinates, (3) ending X coordinates, (4) ending Y coordinates. The first part of this command {{{rep(1<span>23</span>,85)}}} uses the {{{rep}}} command to generate a vector that contains the value {{{1<span>23</span>}}} repeated 85 times. We're doing this because we want to create a line for each of the 85 taxa in our tree, and we want all of these lines to start at an x-value of {{{1<span>23</span>}}} (you may find that you need to adjust this value on a case-by-case basis to make the lines appear where you want them relative to the tips of your tree). The next command {{{1:85}}} tells R that we want lines to begin at integer values ranging from 1-85 on the Y axis: by convention, the tips of phylogentic trees are found at integer values along the Y axis. The next part of this command {{{rep(1<span>23</span>,85) + SVL[anolisComparativeTree$tip.label]}}}} tells R how far lines will extend along the X-axis, in this case, they're going to be as long as the SVL value for the species in our dataset. The final part tells R that our segments will be horizontal lines by repeating the vector with integer values ranging from 1 to 85 for the final Y coordinates of each line. </td> </tr> </table> </div> III. Loading Character Data into Rhttp://bodegaphylo.wikispot.org/III._Loading_Character_Data_into_R2011-02-04 15:14:34(quick edit) <div id="content" class="wikipage content"> Differences for III. Loading Character Data into R<p><strong></strong></p><table> <tr> <td> <span> Deletions are marked with - . </span> </td> <td> <span> Additions are marked with +. </span> </td> </tr> <tr> <td> Line 101: </td> <td> Line 101: </td> </tr> <tr> <td> <span>-</span> This command is broken down into three parts: (1) starting X coordinates, (2) starting Y coordinates, (3) ending X coordinates, (4) ending Y coordinates. The first part of this command {{{rep(101.5,85)}}} uses the {{{rep}}} command to generate a vector that contains the value {{{101.5}}} repeated 85 times. We're doing this because we want to create a line for each of the 85 taxa in our tree, and we want all of these lines to start at an x-value of {{{101.5}}} (you may find that you need to adjust this value on a case-by-case basis to make the lines appear where you want them relative to the tips of your tree). The next command {{{1:85}}} tells R that we want lines to begin at integer values ranging from 1-85 on the Y axis: by convention, the tips of phylogentic trees are found at integer values along the Y axis. The next part of this command {{{rep(101.5,85) + SVL[anolisComparativeTree$tip.label]}}}} tells R how far lines will extend along the X-axis, in this case, they're going to be as long as the SVL value for the species in our dataset. The final part tells R that our segmets will be horizontal lines by repeating the vector with integer values ranging from 1 to 85 for the final Y coordinates of each line. </td> <td> <span>+</span> This command is broken down into three parts: (1) starting X coordinates, (2) starting Y coordinates, (3) ending X coordinates, (4) ending Y coordinates. The first part of this command {{{rep(101.5,85)}}} uses the {{{rep}}} command to generate a vector that contains the value {{{101.5}}} repeated 85 times. We're doing this because we want to create a line for each of the 85 taxa in our tree, and we want all of these lines to start at an x-value of {{{101.5}}} (you may find that you need to adjust this value on a case-by-case basis to make the lines appear where you want them relative to the tips of your tree). The next command {{{1:85}}} tells R that we want lines to begin at integer values ranging from 1-85 on the Y axis: by convention, the tips of phylogentic trees are found at integer values along the Y axis. The next part of this command {{{rep(101.5,85) + SVL[anolisComparativeTree$tip.label]}}}} tells R how far lines will extend along the X-axis, in this case, they're going to be as long as the SVL value for the species in our dataset. The final part tells R that our segme<span>n</span>ts will be horizontal lines by repeating the vector with integer values ranging from 1 to 85 for the final Y coordinates of each line. </td> </tr> </table> </div> III. Loading Character Data into Rhttp://bodegaphylo.wikispot.org/III._Loading_Character_Data_into_R2010-09-28 18:50:53direct link to data -- people didn't pick up on it on Intro page -- BrianO'Meara <div id="content" class="wikipage content"> Differences for III. Loading Character Data into R<p><strong></strong></p><table> <tr> <td> <span> Deletions are marked with - . </span> </td> <td> <span> Additions are marked with +. </span> </td> </tr> <tr> <td> Line 16: </td> <td> Line 16: </td> </tr> <tr> <td> <span>-</span> I’ve provided you with a comma-delimited table of data called <span>{{{anoli</span>s_data.csv<span>}}}</span>. This file contains ecological and morphological data for Greater Antillean Anolis lizards. This file includes three columns: the first contains species names, the second includes discretely coded information about anole microhabitat specialization (0=grass-bush, 1=trunk-ground, 2=trunk, 3=trunk-crown, 4=crown-giant, 5=twig), and the third contains continuously-coded data on adult body size of adult males (measured as the snout to vent length, or SVL). </td> <td> <span>+</span> I’ve provided you with a comma-delimited table of data called <span>[http://bodegaphylo.wikispot.org/Phylogenetic</span>s_<span>and_Comparative_Methods_in_R?action=Files&amp;do=view&amp;target=anolis_</span>data.csv<span>&nbsp;anolis_data.csv]</span>. This file contains ecological and morphological data for Greater Antillean Anolis lizards. This file includes three columns: the first contains species names, the second includes discretely coded information about anole microhabitat specialization (0=grass-bush, 1=trunk-ground, 2=trunk, 3=trunk-crown, 4=crown-giant, 5=twig), and the third contains continuously-coded data on adult body size of adult males (measured as the snout to vent length, or SVL). </td> </tr> </table> </div> III. Loading Character Data into Rhttp://bodegaphylo.wikispot.org/III._Loading_Character_Data_into_R2009-03-24 07:51:11glor <div id="content" class="wikipage content"> Differences for III. Loading Character Data into R<p><strong></strong></p><table> <tr> <td> <span> Deletions are marked with - . </span> </td> <td> <span> Additions are marked with +. </span> </td> </tr> <tr> <td> Line 97: </td> <td> Line 97: </td> </tr> <tr> <td> <span>-</span> '''d.''' Now let's add scale bars that indicate the size of each species to this tree. The way we're going to do this is by telling R to make {{{segments}}} at the tips of our tree that scale with body size. </td> <td> <span>+</span> '''d.''' Now let's add scale bars that indicate the size of each species to this tree. The way we're going to do this is by telling R to make {{{segments}}} at the tips of our tree that scale with body size.<span>&nbsp;&nbsp;The {{{segments}}} command works by connecting points in R's X/Y coordinate space with a line, or segment. We're going to use this command to make a series of lines connecting two points using the following command:</span> </td> </tr> <tr> <td> Line 101: </td> <td> Line 101: </td> </tr> <tr> <td> </td> <td> <span>+ This command is broken down into three parts: (1) starting X coordinates, (2) starting Y coordinates, (3) ending X coordinates, (4) ending Y coordinates. The first part of this command {{{rep(101.5,85)}}} uses the {{{rep}}} command to generate a vector that contains the value {{{101.5}}} repeated 85 times. We're doing this because we want to create a line for each of the 85 taxa in our tree, and we want all of these lines to start at an x-value of {{{101.5}}} (you may find that you need to adjust this value on a case-by-case basis to make the lines appear where you want them relative to the tips of your tree). The next command {{{1:85}}} tells R that we want lines to begin at integer values ranging from 1-85 on the Y axis: by convention, the tips of phylogentic trees are found at integer values along the Y axis. The next part of this command {{{rep(101.5,85) + SVL[anolisComparativeTree$tip.label]}}}} tells R how far lines will extend along the X-axis, in this case, they're going to be as long as the SVL value for the species in our dataset. The final part tells R that our segmets will be horizontal lines by repeating the vector with integer values ranging from 1 to 85 for the final Y coordinates of each line.<br> + <br> + </span> </td> </tr> </table> </div> III. Loading Character Data into Rhttp://bodegaphylo.wikispot.org/III._Loading_Character_Data_into_R2009-03-23 12:18:19YStuart(quick edit) <div id="content" class="wikipage content"> Differences for III. Loading Character Data into R<p><strong></strong></p><table> <tr> <td> <span> Deletions are marked with - . </span> </td> <td> <span> Additions are marked with +. </span> </td> </tr> <tr> <td> Line 99: </td> <td> Line 99: </td> </tr> <tr> <td> <span>-</span> {{{ &gt;segments(rep(<span>76</span>.5,85), 1:85, rep(<span>76</span>.5,85) + SVL[anolisComparativeTree$tip.label], 1:85, lwd=2)}}} </td> <td> <span>+</span> {{{ &gt;segments(rep(<span>101</span>.5,85), 1:85, rep(<span>101</span>.5,85) + SVL[anolisComparativeTree$tip.label], 1:85, lwd=2)}}} </td> </tr> </table> </div> III. Loading Character Data into Rhttp://bodegaphylo.wikispot.org/III._Loading_Character_Data_into_R2009-03-23 12:17:41YStuart(quick edit) <div id="content" class="wikipage content"> Differences for III. Loading Character Data into R<p><strong></strong></p><table> <tr> <td> <span> Deletions are marked with - . </span> </td> <td> <span> Additions are marked with +. </span> </td> </tr> <tr> <td> Line 93: </td> <td> Line 93: </td> </tr> <tr> <td> <span>-</span> {{{points(rep(<span>75</span>.5, length(anolisComparativeTree$tip.label)), 1:length(anolisComparativeTree$tip.label), pch=22, bg=microLabel[anolisComparativeTree$tip.label], cex=0.5, lwd=0.25)}}} </td> <td> <span>+</span> {{{points(rep(<span>100</span>.5, length(anolisComparativeTree$tip.label)), 1:length(anolisComparativeTree$tip.label), pch=22, bg=microLabel[anolisComparativeTree$tip.label], cex=0.5, lwd=0.25)}}} </td> </tr> </table> </div> III. Loading Character Data into Rhttp://bodegaphylo.wikispot.org/III._Loading_Character_Data_into_R2009-03-13 14:55:23glor <div id="content" class="wikipage content"> Differences for III. Loading Character Data into R<p><strong></strong></p><table> <tr> <td> <span> Deletions are marked with - . </span> </td> <td> <span> Additions are marked with +. </span> </td> </tr> <tr> <td> Line 6: </td> <td> Line 6: </td> </tr> <tr> <td> <span>- ==='''Introduction'''===</span> </td> <td> <span>+ --&gt;["Phylogenetics and Comparative Methods in R" Introduction]|["I. Getting Started with R" I. Getting Started]|["II. Tree Basics" II. Tree Basics]|["III. Loading Character Data into R" III. Loading Character Data]|["IV. Testing Phylogenetic Signal in R" IV. Testing Phylogenetic Signal]|["V. Ancestral Reconstruction with Maximum Likelihood on Discrete Traits in R" V. Ancestral Reconstruction]|["VI. Testing Temporal Patterns of Character Evolution in R" VI. Testing Patterns]&lt;--<br> + <br> + ==Introduction==</span> </td> </tr> <tr> <td> Line 10: </td> <td> Line 12: </td> </tr> <tr> <td> <span>-</span> ===<span>'''</span>A. Loading trait data into R<span>'''</span>=== </td> <td> <span>+</span> ===A. Loading trait data into R=== </td> </tr> <tr> <td> Line 51: </td> <td> Line 53: </td> </tr> <tr> <td> <span>-</span> ===<span>'''</span>B. Checking overlap of phylogenetic and trait datasets<span>'''</span>=== </td> <td> <span>+</span> ===B. Checking overlap of phylogenetic and trait datasets=== </td> </tr> <tr> <td> Line 68: </td> <td> Line 70: </td> </tr> <tr> <td> <span>-</span> ===<span>'''</span>C. Visualizing Trait Data on a Phylogeny<span>'''</span>=== </td> <td> <span>+</span> ===C. Visualizing Trait Data on a Phylogeny=== </td> </tr> </table> </div> III. Loading Character Data into Rhttp://bodegaphylo.wikispot.org/III._Loading_Character_Data_into_R2009-03-10 14:52:44glor <div id="content" class="wikipage content"> Differences for III. Loading Character Data into R<p><strong></strong></p><table> <tr> <td> <span> Deletions are marked with - . </span> </td> <td> <span> Additions are marked with +. </span> </td> </tr> <tr> <td> Line 4: </td> <td> Line 4: </td> </tr> <tr> <td> <span>-</span> ||See part <span>["I. G</span>et<span>t</span>in<span>g Started with</span> R" I]||R for Phylogenetics parts ["I. Getting Started with R" I], ["II. Tree Basics" II]|| </td> <td> <span>+</span> ||See <span>["Phylogenetics and Com</span>par<span>a</span>t<span>ive</span> <span>M</span>et<span>hods </span>in R" I<span>ntroduction</span>]||R for Phylogenetics parts ["I. Getting Started with R" I], ["II. Tree Basics" II]|| </td> </tr> </table> </div> III. Loading Character Data into Rhttp://bodegaphylo.wikispot.org/III._Loading_Character_Data_into_R2009-03-10 14:46:34glor <div id="content" class="wikipage content"> Differences for III. Loading Character Data into R<p><strong></strong></p><table> <tr> <td> <span> Deletions are marked with - . </span> </td> <td> <span> Additions are marked with +. </span> </td> </tr> <tr> <td> Line 100: </td> <td> Line 100: </td> </tr> <tr> <td> <span>-</span> ====Continue to part IV: ["IV. Testing Phylogenetic Signal in R"]==== </td> <td> <span>+</span> ====Continue to part IV: ["IV. Testing Phylogenetic Signal in R"<span>&nbsp;Testing Phylogenetic Signal in R</span>]==== </td> </tr> </table> </div> III. Loading Character Data into Rhttp://bodegaphylo.wikispot.org/III._Loading_Character_Data_into_R2009-03-10 14:46:02glor <div id="content" class="wikipage content"> Differences for III. Loading Character Data into R<p><strong></strong></p><table> <tr> <td> <span> Deletions are marked with - . </span> </td> <td> <span> Additions are marked with +. </span> </td> </tr> <tr> <td> Line 100: </td> <td> Line 100: </td> </tr> <tr> <td> <span>-</span> ====Continue to part IV: ["Testing Phylogenetic Signal in R"]==== </td> <td> <span>+</span> ====Continue to part IV: ["<span>IV. </span>Testing Phylogenetic Signal in R"]==== </td> </tr> </table> </div> III. Loading Character Data into Rhttp://bodegaphylo.wikispot.org/III._Loading_Character_Data_into_R2009-03-10 14:44:23glor <div id="content" class="wikipage content"> Differences for III. Loading Character Data into R<p><strong></strong></p><table> <tr> <td> <span> Deletions are marked with - . </span> </td> <td> <span> Additions are marked with +. </span> </td> </tr> <tr> <td> Line 80: </td> <td> Line 80: </td> </tr> <tr> <td> <span>- microLabel[micro==0] &lt;- "blue"<br> - microLabel[micro==1] &lt;- "red"<br> - microLabel[micro==2] &lt;- "yellow"<br> - microLabel[micro==3] &lt;- "orange"<br> - microLabel[micro==4] &lt;- "green"<br> - microLabel[micro==5] &lt;- "gray"}}}</span> </td> <td> <span>+ microLabel[micro==0] &lt;- "red"<br> + microLabel[micro==1] &lt;- "yellow"<br> + microLabel[micro==2] &lt;- "green"<br> + microLabel[micro==3] &lt;- "light blue"<br> + microLabel[micro==4] &lt;- "blue"<br> + microLabel[micro==5] &lt;- "purple"}}}</span> </td> </tr> </table> </div> III. Loading Character Data into Rhttp://bodegaphylo.wikispot.org/III._Loading_Character_Data_into_R2009-03-10 14:42:33glor <div id="content" class="wikipage content"> Differences for III. Loading Character Data into R<p><strong></strong></p><table> <tr> <td> <span> Deletions are marked with - . </span> </td> <td> <span> Additions are marked with +. </span> </td> </tr> <tr> <td> Line 55: </td> <td> Line 55: </td> </tr> <tr> <td> <span>-</span> '''1.''' Let’s consider the two datasets from Anolis lizards that we’ve already loaded into R, which include a phylogenetic tree ({{{anolisTree<span>}}}</span>) and data on microhabitat specialization and body size ({{{anolisData}}}). To determine which taxa are overlapping in these two files, type: </td> <td> <span>+</span> '''1.''' Let’s consider the two datasets from Anolis lizards that we’ve already loaded into R, which include a phylogenetic tree ({{{anolis<span>Chronogram}}} - this tree was made during Part ["II. </span>Tree<span>&nbsp;Basics" II] of this exercise, so go back and complete this exercise if you don't still have this tree stored in R</span>) and data on microhabitat specialization and body size ({{{anolisData}}}). To determine which taxa are overlapping in these two files, type: </td> </tr> <tr> <td> Line 57: </td> <td> Line 57: </td> </tr> <tr> <td> <span>-</span> {{{ &gt;name.check(anolis<span>T</span>r<span>ee</span>, anolisData)}}} </td> <td> <span>+</span> {{{ &gt;name.check(anolis<span>Ch</span>r<span>onogram</span>, anolisData)}}} </td> </tr> <tr> <td> Line 63: </td> <td> Line 63: </td> </tr> <tr> <td> <span>-</span> {{{ &gt;name.check(anolis<span>T</span>r<span>ee</span>, anolisData) -&gt; anolisOverlap<br> <span>-</span> &gt;drop.tip(anolis<span>T</span>r<span>ee</span>, anolisOverlap$Tree.not.data) -&gt; anolisComparativeTree}}} </td> <td> <span>+</span> {{{ &gt;name.check(anolis<span>Ch</span>r<span>onogram</span>, anolisData) -&gt; anolisOverlap<br> <span>+</span> &gt;drop.tip(anolis<span>Ch</span>r<span>onogram</span>, anolisOverlap$Tree.not.data) -&gt; anolisComparativeTree}}} </td> </tr> </table> </div> III. Loading Character Data into Rhttp://bodegaphylo.wikispot.org/III._Loading_Character_Data_into_R2009-03-10 14:40:31glor <div id="content" class="wikipage content"> Differences for III. Loading Character Data into R<p><strong></strong></p><table> <tr> <td> <span> Deletions are marked with - . </span> </td> <td> <span> Additions are marked with +. </span> </td> </tr> <tr> <td> Line 4: </td> <td> Line 4: </td> </tr> <tr> <td> <span>-</span> ||[<span>[F</span>i<span>l</span>e<span>(anol</span>i<span>s_m</span>t<span>DNA.mrb.con)]</span>]||R for Phylogenetics parts ["I. Getting Started with R" I]<span>&nbsp;and</span> ["II. Tree Basics" II]||<span>||<br> - ||[[File(anolis_data.csv)]]||</span> </td> <td> <span>+</span> ||<span>See part </span>[<span>"I. Gett</span>i<span>ng Start</span>e<span>d w</span>it<span>h R" I</span>]||R for Phylogenetics parts ["I. Getting Started with R" I]<span>,</span> ["II. Tree Basics" II]|| </td> </tr> </table> </div> III. Loading Character Data into Rhttp://bodegaphylo.wikispot.org/III._Loading_Character_Data_into_R2009-03-10 13:45:42glor <div id="content" class="wikipage content"> Differences for III. Loading Character Data into R<p><strong></strong></p><table> <tr> <td> <span> Deletions are marked with - . </span> </td> <td> <span> Additions are marked with +. </span> </td> </tr> <tr> <td> Line 101: </td> <td> Line 101: </td> </tr> <tr> <td> <span>-</span> ====Continue to part IV: ["<span>IV. </span>Testing Phylogenetic Signal in R"]==== </td> <td> <span>+</span> ====Continue to part IV: ["Testing Phylogenetic Signal in R"]==== </td> </tr> </table> </div> III. Loading Character Data into Rhttp://bodegaphylo.wikispot.org/III._Loading_Character_Data_into_R2009-03-10 13:45:20glor <div id="content" class="wikipage content"> Differences for III. Loading Character Data into R<p><strong></strong></p><table> <tr> <td> <span> Deletions are marked with - . </span> </td> <td> <span> Additions are marked with +. </span> </td> </tr> <tr> <td> Line 99: </td> <td> Line 99: </td> </tr> <tr> <td> </td> <td> <span>+ <br> + -----<br> + ====Continue to part IV: ["IV. Testing Phylogenetic Signal in R"]====</span> </td> </tr> </table> </div> III. Loading Character Data into Rhttp://bodegaphylo.wikispot.org/III._Loading_Character_Data_into_R2009-03-10 13:33:58glor <div id="content" class="wikipage content"> Differences for III. Loading Character Data into R<p><strong></strong></p><table> <tr> <td> <span> Deletions are marked with - . </span> </td> <td> <span> Additions are marked with +. </span> </td> </tr> <tr> <td> Line 79: </td> <td> Line 79: </td> </tr> <tr> <td> <span>-</span> {{{microLabel &lt;- character(length(anolisComparativeTree<span>&nbsp;</span>$tip.label)) </td> <td> <span>+</span> {{{microLabel &lt;- character(length(anolisComparativeTree$tip.label)) </td> </tr> <tr> <td> Line 92: </td> <td> Line 92: </td> </tr> <tr> <td> <span>-</span> <span>{{{</span> points(rep(75.5, length(anolisComparativeTree$tip.label)), 1:length(anolisComparativeTree$tip.label), pch=22, bg=microLabel[anolisComparativeTree$tip.label], cex=0.5, lwd=0.25)}}} </td> <td> <span>+</span> <span>{{{</span>points(rep(75.5, length(anolisComparativeTree$tip.label)), 1:length(anolisComparativeTree$tip.label), pch=22, bg=microLabel[anolisComparativeTree$tip.label], cex=0.5, lwd=0.25)}}}<span><br> + <br> + NOTE: The {{{points}}} command will only work if you already have a plotting window open. This is because {{{points}}} is trying to add points to an already existing figure. Go back and repeat the plotting function implemented in step 1a if you closed your {{{Quartz}}} window between then and now.</span> </td> </tr> </table> </div> III. Loading Character Data into Rhttp://bodegaphylo.wikispot.org/III._Loading_Character_Data_into_R2009-03-10 13:11:39glor <div id="content" class="wikipage content"> Differences for III. Loading Character Data into R<p><strong></strong></p><table> <tr> <td> <span> Deletions are marked with - . </span> </td> <td> <span> Additions are marked with +. </span> </td> </tr> <tr> <td> Line 49: </td> <td> Line 49: </td> </tr> <tr> <td> <span>-</span> {{{<span>&nbsp;</span>&gt;names(micro) &lt;- rownames(anolisData) </td> <td> <span>+</span> <span>&nbsp;</span> {{{&gt;names(micro) &lt;- rownames(anolisData) </td> </tr> </table> </div> III. Loading Character Data into Rhttp://bodegaphylo.wikispot.org/III._Loading_Character_Data_into_R2009-03-10 13:10:16glor <div id="content" class="wikipage content"> Differences for III. Loading Character Data into R<p><strong></strong></p><table> <tr> <td> <span> Deletions are marked with - . </span> </td> <td> <span> Additions are marked with +. </span> </td> </tr> <tr> <td> Line 72: </td> <td> Line 72: </td> </tr> <tr> <td> <span>- '''a.''' First plot the basic tree:<br> - {{{ &gt;plot(anolisComparativeTree, x.lim=100, show.tip.label=FALSE)}}}</span> </td> <td> <span>+ '''a.''' We first want to plot a basic tree. Let's try looking at our data on an ultrametric tree. Ordinarily, you'd want import an ultrametric tree into R from a program like BEAST. For simplicity, however, we're just going to look at a tree generated using the non-parametric rate-smoothing function (NPRS) that is implemented internally by R.<br> + <br> + {{{&gt;chronogram(anolisComparativeTree, scale=100) -&gt; anolisChronogram<br> + &gt;plot(anolisChronogram, x.lim=100, show.tip.label=FALSE)}}}</span> </td> </tr> </table> </div> III. Loading Character Data into Rhttp://bodegaphylo.wikispot.org/III._Loading_Character_Data_into_R2009-03-10 13:05:19glor <div id="content" class="wikipage content"> Differences for III. Loading Character Data into R<p><strong></strong></p><table> <tr> <td> <span> Deletions are marked with - . </span> </td> <td> <span> Additions are marked with +. </span> </td> </tr> <tr> <td> Line 3: </td> <td> Line 3: </td> </tr> <tr> <td> <span>-</span> ||&lt;bgcolor='#E0E0FF'&gt;'''Example Datafile'''||&lt;bgcolor='#E0E0FF'&gt;'''Prerequisites'''||<br> <span>-</span> ||[[File(anolis_mtDNA.mrb.con)]]||R for Phylogenetics parts ["I. Getting Started with R" I] and ["II. Tree Basics" II]|| </td> <td> <span>+</span> ||&lt;bgcolor='#E0E0FF'&gt;'''Example Datafile'''||&lt;bgcolor='#E0E0FF'&gt;'''Prerequisites'''||<span>&lt;bgcolor='#E0E0FF'&gt;||</span><br> <span>+</span> ||[[File(anolis_mtDNA.mrb.con)]]||R for Phylogenetics parts ["I. Getting Started with R" I] and ["II. Tree Basics" II]||<span>||</span> </td> </tr> </table> </div> III. Loading Character Data into Rhttp://bodegaphylo.wikispot.org/III._Loading_Character_Data_into_R2009-03-10 13:04:44glor <div id="content" class="wikipage content"> Differences for III. Loading Character Data into R<p><strong></strong></p><table> <tr> <td> <span> Deletions are marked with - . </span> </td> <td> <span> Additions are marked with +. </span> </td> </tr> <tr> <td> Line 1: </td> <td> Line 1: </td> </tr> <tr> <td> <span>-</span> ||&lt;bgcolor='#E0E0FF'&gt;'''Primary Contact(s)'''||&lt;bgcolor='#E0E0FF'&gt;'''Created'''<span>||<br> - ||["Users/glor" Rich Glor]||7 March 2009||<br> - </span>||&lt;bgcolor='#E0E0FF'&gt;'''Required Software'''||<br> <span>- </span>||[http://cran.r-project.org/ R]||<br> <span>-</span> ||&lt;bgcolor='#E0E0FF'&gt;'''Example Datafile'''||<br> <span>-</span> ||[[File(anolis_mtDNA.mrb.con)]]|| </td> <td> <span>+</span> ||&lt;bgcolor='#E0E0FF'&gt;'''Primary Contact(s)'''||&lt;bgcolor='#E0E0FF'&gt;'''Created'''||&lt;bgcolor='#E0E0FF'&gt;'''Required Software'''||<br> <span>+ ||["Users/glor" Rich Glor]||7 March 2009</span>||[http://cran.r-project.org/ R]||<br> <span>+</span> ||&lt;bgcolor='#E0E0FF'&gt;'''Example Datafile'''||<span>&lt;bgcolor='#E0E0FF'&gt;'''Prerequisites'''||</span><br> <span>+</span> ||[[File(anolis_mtDNA.mrb.con)]]||<span>R for Phylogenetics parts ["I. Getting Started with R" I] and ["II. Tree Basics" II]||</span> </td> </tr> <tr> <td> Line 8: </td> <td> Line 6: </td> </tr> <tr> <td> <span>- ||&lt;bgcolor='#E0E0FF'&gt;'''Prerequisites'''||<br> - ||R for Phylogenetics parts ["I. Getting Started with R" I] and ["II. Tree Basics" II]||</span> </td> <td> </td> </tr> </table> </div> III. Loading Character Data into Rhttp://bodegaphylo.wikispot.org/III._Loading_Character_Data_into_R2009-03-10 13:03:52glor <div id="content" class="wikipage content"> Differences for III. Loading Character Data into R<p><strong></strong></p><table> <tr> <td> <span> Deletions are marked with - . </span> </td> <td> <span> Additions are marked with +. </span> </td> </tr> <tr> <td> Line 1: </td> <td> Line 1: </td> </tr> <tr> <td> <span>-</span> ||&lt;bgcolor='#E0E0FF'&gt;'''Primary Contact(s)'''||<span><br> - ||["Users/glor" Rich Glor]||<br> - ||</span>&lt;bgcolor='#E0E0FF'&gt;'''Created'''||<br> <span>-</span> ||7 March 2009|| </td> <td> <span>+</span> ||&lt;bgcolor='#E0E0FF'&gt;'''Primary Contact(s)'''||&lt;bgcolor='#E0E0FF'&gt;'''Created'''||<br> <span>+</span> <span>||["Users/glor" Rich Glor]</span>||7 March 2009|| </td> </tr> </table> </div> III. Loading Character Data into Rhttp://bodegaphylo.wikispot.org/III._Loading_Character_Data_into_R2009-03-09 12:26:12glor <div id="content" class="wikipage content"> Differences for III. Loading Character Data into R<p><strong></strong></p><table> <tr> <td> <span> Deletions are marked with - . </span> </td> <td> <span> Additions are marked with +. </span> </td> </tr> <tr> <td> Line 96: </td> <td> Line 96: </td> </tr> <tr> <td> <span>-</span> {{{ points(rep(75, length(anolisComparativeTree$tip.label)), 1:length(anolisComparativeTree$tip.label), pch=22, bg=microLabel[anolisComparativeTree$tip.label], cex=0.5, lwd=0.25)}}} </td> <td> <span>+</span> {{{ points(rep(7<span>5.</span>5, length(anolisComparativeTree$tip.label)), 1:length(anolisComparativeTree$tip.label), pch=22, bg=microLabel[anolisComparativeTree$tip.label], cex=0.5, lwd=0.25)}}} </td> </tr> <tr> <td> Line 100: </td> <td> Line 100: </td> </tr> <tr> <td> <span>- {{{ &gt;segments(rep(95,85), 1:85, rep(95,85) + SVL[anolisComparativeTree$tip.label], 1:85, lwd=2)}}}<br> - <br> - '''e.''' Finally, we can add a labeled axis to the scale bars.<br> - {{{ &gt;axis(1,at=c(75,max(SVL)), labels=c(0,5.5))<br> - &gt;mtext("lnSVL", at=98, side=1, line=2) #adds label to SVL bars}}}</span> </td> <td> <span>+ {{{ &gt;segments(rep(76.5,85), 1:85, rep(76.5,85) + SVL[anolisComparativeTree$tip.label], 1:85, lwd=2)}}}</span> </td> </tr> </table> </div> III. Loading Character Data into Rhttp://bodegaphylo.wikispot.org/III._Loading_Character_Data_into_R2009-03-09 12:17:55glor <div id="content" class="wikipage content"> Differences for III. Loading Character Data into R<p><strong></strong></p><table> <tr> <td> <span> Deletions are marked with - . </span> </td> <td> <span> Additions are marked with +. </span> </td> </tr> <tr> <td> Line 81: </td> <td> Line 81: </td> </tr> <tr> <td> <span>- '''b.''' Now let's add scale bars that indicate the size of each species to this tree. The way we're going to do this is by telling R to make {{{segments}}} at the tips of our tree that scale with body size.</span> </td> <td> <span>+ '''b.''' Now let's add colored boxes to indicate microhabitat specialist states. This may seem a bit complicated at first, but you'll appreciate the flexibility of the method if you stick with it. We're going to start by making a dummy vector that is formatted to store character data. The names of the cells in this dummy vector will correspond with the names of our tip taxa. We're soon going to fill this vector in with the names of the colors we'd like to use for labeling.</span> </td> </tr> <tr> <td> Line 83: </td> <td> Line 83: </td> </tr> <tr> <td> <span>- {{{ &gt;segments(rep(95,85), 1:85, rep(95,85) + SVL[anolisComparativeTree$tip.label], 1:85, lwd=2)</span> </td> <td> <span>+ {{{microLabel &lt;- character(length(anolisComparativeTree $tip.label))<br> + names(microLabel) &lt;- names(micro)<br> + microLabel[micro==0] &lt;- "blue"<br> + microLabel[micro==1] &lt;- "red"<br> + microLabel[micro==2] &lt;- "yellow"<br> + microLabel[micro==3] &lt;- "orange"<br> + microLabel[micro==4] &lt;- "green"<br> + microLabel[micro==5] &lt;- "gray"}}}</span> </td> </tr> <tr> <td> Line 85: </td> <td> Line 92: </td> </tr> <tr> <td> <span>- BELOW IS NOT FINISHED YET...<br> - '''b.''' Finally, we can add a labeled axis to the scale bars.<br> - {{{ &gt;axis(1,at=c(75,100), labels=c(0,5.5))</span> </td> <td> <span>+ If you type {{{microLabel}}} now, you should see a vector of names and associated colors.<br> + <br> + '''c.''' Our next challenge is to plot these colors across the tips of our tree. To do this, we're going to use the {{{points}}} command. This command is used to give the X and Y coordinates of places on our figure where we'd like to place points. We can also specify what types of points we'd like to use with the {{{pch}}} command and what color we'd like these points to be using the previously generated {{{microLabel}}} vector.<br> + <br> + {{{ points(rep(75, length(anolisComparativeTree$tip.label)), 1:length(anolisComparativeTree$tip.label), pch=22, bg=microLabel[anolisComparativeTree$tip.label], cex=0.5, lwd=0.25)}}}<br> + <br> + '''d.''' Now let's add scale bars that indicate the size of each species to this tree. The way we're going to do this is by telling R to make {{{segments}}} at the tips of our tree that scale with body size.<br> + <br> + {{{ &gt;segments(rep(95,85), 1:85, rep(95,85) + SVL[anolisComparativeTree$tip.label], 1:85, lwd=2)}}}<br> + <br> + '''e.''' Finally, we can add a labeled axis to the scale bars.<br> + {{{ &gt;axis(1,at=c(75,max(SVL)), labels=c(0,5.5))</span> </td> </tr> </table> </div> III. Loading Character Data into Rhttp://bodegaphylo.wikispot.org/III._Loading_Character_Data_into_R2009-03-09 09:57:25glor <div id="content" class="wikipage content"> Differences for III. Loading Character Data into R<p><strong></strong></p><table> <tr> <td> <span> Deletions are marked with - . </span> </td> <td> <span> Additions are marked with +. </span> </td> </tr> <tr> <td> Line 83: </td> <td> Line 83: </td> </tr> <tr> <td> <span>-</span> {{{ &gt;segments(rep(95,85), 1:85, rep(95,85) + SVL[anolisComparativeTree$tip.label], 1:85, lwd=2)<span>&nbsp;#uses the segments command to draw appropriately scaled lines next to each terminal node</span> </td> <td> <span>+</span> {{{ &gt;segments(rep(95,85), 1:85, rep(95,85) + SVL[anolisComparativeTree$tip.label], 1:85, lwd=2) </td> </tr> <tr> <td> Line 85: </td> <td> Line 85: </td> </tr> <tr> <td> <span>- &gt;axisPhylo()<br> - &gt;segments(rep(95,85), 1:85, rep(95,85) + lnSVL[anolisComparativeTree$tip.label], 1:85, lwd=2) #uses the segments command to draw appropriately scaled lines next to each terminal node<br> - &gt;axis(1,at=c(95,100), labels=c(0,5.5)) #adds axis to scaled SVL bars<br> - &gt;mtext("lnSVL", at=98, side=1, line=2) #adds label to SVL bars}}}</span> </td> <td> <span>+ BELOW IS NOT FINISHED YET...<br> + '''b.''' Finally, we can add a labeled axis to the scale bars.<br> + {{{ &gt;axis(1,at=c(75,100), labels=c(0,5.5))<br> + &gt;mtext("lnSVL", at=98, side=1, line=2) #adds label to SVL bars}}}</span> </td> </tr> </table> </div> III. Loading Character Data into Rhttp://bodegaphylo.wikispot.org/III._Loading_Character_Data_into_R2009-03-09 09:09:33glor <div id="content" class="wikipage content"> Differences for III. Loading Character Data into R<p><strong></strong></p><table> <tr> <td> <span> Deletions are marked with - . </span> </td> <td> <span> Additions are marked with +. </span> </td> </tr> <tr> <td> Line 39: </td> <td> Line 39: </td> </tr> <tr> <td> <span>-</span> {{{ &gt;anolisData[,2] &lt;- log(anolisData[,2]}}} </td> <td> <span>+</span> {{{ &gt;anolisData[,2] &lt;- log(anolisData[,2]<span>)</span>}}} </td> </tr> <tr> <td> Line 78: </td> <td> Line 78: </td> </tr> <tr> <td> <span>- '''b.''' First plot the basic tree:<br> - {{{ &gt;plot(anolisComparativeTree, x.lim=100, show.tip.label=FALSE)</span> </td> <td> <span>+ '''a.''' First plot the basic tree:<br> + {{{ &gt;plot(anolisComparativeTree, x.lim=100, show.tip.label=FALSE)}}}<br> + <br> + '''b.''' Now let's add scale bars that indicate the size of each species to this tree. The way we're going to do this is by telling R to make {{{segments}}} at the tips of our tree that scale with body size.<br> + <br> + {{{ &gt;segments(rep(95,85), 1:85, rep(95,85) + SVL[anolisComparativeTree$tip.label], 1:85, lwd=2) #uses the segments command to draw appropriately scaled lines next to each terminal node</span> </td> </tr> </table> </div> III. Loading Character Data into Rhttp://bodegaphylo.wikispot.org/III._Loading_Character_Data_into_R2009-03-09 09:04:06glor <div id="content" class="wikipage content"> Differences for III. Loading Character Data into R<p><strong></strong></p><table> <tr> <td> <span> Deletions are marked with - . </span> </td> <td> <span> Additions are marked with +. </span> </td> </tr> <tr> <td> Line 56: </td> <td> Line 56: </td> </tr> <tr> <td> <span>-</span> <span>&nbsp;</span>&gt;names(SVL) &lt;- rownames(anolisData)}}} </td> <td> <span>+</span> &gt;names(SVL) &lt;- rownames(anolisData)}}} </td> </tr> <tr> <td> Line 71: </td> <td> Line 71: </td> </tr> <tr> <td> <span>-</span> <span>&nbsp;</span>&gt;drop.tip(anolisTree, anolisOverlap$Tree.not.data) -&gt; anolisComparativeTree}}} </td> <td> <span>+</span> &gt;drop.tip(anolisTree, anolisOverlap$Tree.not.data) -&gt; anolisComparativeTree}}} </td> </tr> </table> </div> III. Loading Character Data into Rhttp://bodegaphylo.wikispot.org/III._Loading_Character_Data_into_R2009-03-09 09:02:14glor <div id="content" class="wikipage content"> Differences for III. Loading Character Data into R<p><strong></strong></p><table> <tr> <td> <span> Deletions are marked with - . </span> </td> <td> <span> Additions are marked with +. </span> </td> </tr> <tr> <td> Line 71: </td> <td> Line 71: </td> </tr> <tr> <td> <span>-</span> &gt;drop.tip(anolisTree, anolisOverlap$Tree.not.data) -&gt; anolisComparativeTree}}} </td> <td> <span>+</span> <span>&nbsp;</span>&gt;drop.tip(anolisTree, anolisOverlap$Tree.not.data) -&gt; anolisComparativeTree}}} </td> </tr> </table> </div> III. Loading Character Data into Rhttp://bodegaphylo.wikispot.org/III._Loading_Character_Data_into_R2009-03-09 09:01:20glor <div id="content" class="wikipage content"> Differences for III. Loading Character Data into R<p><strong></strong></p><table> <tr> <td> <span> Deletions are marked with - . </span> </td> <td> <span> Additions are marked with +. </span> </td> </tr> <tr> <td> Line 71: </td> <td> Line 71: </td> </tr> <tr> <td> <span>-</span> <span>&nbsp;</span>&gt;drop.tip(anolisTree, anolisOverlap$Tree.not.data) -&gt; anolisComparativeTree}}} </td> <td> <span>+</span> &gt;drop.tip(anolisTree, anolisOverlap$Tree.not.data) -&gt; anolisComparativeTree}}} </td> </tr> </table> </div> III. Loading Character Data into Rhttp://bodegaphylo.wikispot.org/III._Loading_Character_Data_into_R2009-03-09 09:00:27glor <div id="content" class="wikipage content"> Differences for III. Loading Character Data into R<p><strong></strong></p><table> <tr> <td> <span> Deletions are marked with - . </span> </td> <td> <span> Additions are marked with +. </span> </td> </tr> <tr> <td> Line 56: </td> <td> Line 56: </td> </tr> <tr> <td> <span>-</span> <span>&nbsp;</span> &gt;names(SVL) &lt;- rownames(anolisData)}}} </td> <td> <span>+</span> &gt;names(SVL) &lt;- rownames(anolisData)}}} </td> </tr> </table> </div> III. Loading Character Data into Rhttp://bodegaphylo.wikispot.org/III._Loading_Character_Data_into_R2009-03-09 08:59:11glor <div id="content" class="wikipage content"> Differences for III. Loading Character Data into R<p><strong></strong></p><table> <tr> <td> <span> Deletions are marked with - . </span> </td> <td> <span> Additions are marked with +. </span> </td> </tr> <tr> <td> Line 37: </td> <td> Line 37: </td> </tr> <tr> <td> <span>- '''b.''' Now let’s add names to the rows in our dataframe by telling R that these names can be found in the first column of anolis.dat.</span> </td> <td> <span>+ '''b.''' Let's make one more change to this data before going any further by log transforming our body size data. To do this, we're simply going to replace the original raw data with log-transformed data:<br> + <br> + {{{ &gt;anolisData[,2] &lt;- log(anolisData[,2]}}}<br> + <br> + '''c.''' Now let’s add names to the rows in our dataframe by telling R that these names can be found in the first column of anolis.dat.</span> </td> </tr> <tr> <td> Line 43: </td> <td> Line 47: </td> </tr> <tr> <td> <span>-</span> '''<span>c</span>.''' Next we’re going to make our dataframe the default dataframe in R’s system by using the attach function. This will allow us to call elements of the dataframe without constantly making reference to the name of the dataframe itself. Before using the attach command, try typing the name of one of the columns of your dataframe (e.g., micro). You should end up with an error message. Now attach your dataframe by typing: </td> <td> <span>+</span> '''<span>d</span>.''' Next we’re going to make our dataframe the default dataframe in R’s system by using the attach function. This will allow us to call elements of the dataframe without constantly making reference to the name of the dataframe itself. Before using the attach command, try typing the name of one of the columns of your dataframe (e.g., micro). You should end up with an error message. Now attach your dataframe by typing: </td> </tr> <tr> <td> Line 49: </td> <td> Line 53: </td> </tr> <tr> <td> <span>-</span> '''<span>d</span>.''' To make things even easier for subsequent analyses, we're going to reapply taxon names to the microhabitat and body size data. </td> <td> <span>+</span> '''<span>e</span>.''' To make things even easier for subsequent analyses, we're going to reapply taxon names to the microhabitat and body size data. </td> </tr> <tr> <td> Line 70: </td> <td> Line 74: </td> </tr> <tr> <td> </td> <td> <span>+ <br> + ==='''C. Visualizing Trait Data on a Phylogeny'''===<br> + '''1.''' We often would like to plot the data for our comparative analysis across the tips of our tree. With a bit of practice, this can be done fairly easily in R. Let’s plot the data for adult male body size on the tips of our tree for anoles.<br> + <br> + '''b.''' First plot the basic tree:<br> + {{{ &gt;plot(anolisComparativeTree, x.lim=100, show.tip.label=FALSE)<br> + <br> + &gt;axisPhylo()<br> + &gt;segments(rep(95,85), 1:85, rep(95,85) + lnSVL[anolisComparativeTree$tip.label], 1:85, lwd=2) #uses the segments command to draw appropriately scaled lines next to each terminal node<br> + &gt;axis(1,at=c(95,100), labels=c(0,5.5)) #adds axis to scaled SVL bars<br> + &gt;mtext("lnSVL", at=98, side=1, line=2) #adds label to SVL bars}}}</span> </td> </tr> </table> </div> III. Loading Character Data into Rhttp://bodegaphylo.wikispot.org/III._Loading_Character_Data_into_R2009-03-09 08:42:10glor <div id="content" class="wikipage content"> Differences for III. Loading Character Data into R<p><strong></strong></p><table> <tr> <td> <span> Deletions are marked with - . </span> </td> <td> <span> Additions are marked with +. </span> </td> </tr> <tr> <td> Line 51: </td> <td> Line 51: </td> </tr> <tr> <td> <span>-</span> {{{ &gt;names(micro) &lt;- rownames(anolisData)<span>[[br]]</span>&gt;names(SVL) &lt;- rownames(anolisData)}}} </td> <td> <span>+</span> {{{ &gt;names(micro) &lt;- rownames(anolisData)<span><br> + </span>&gt;names(SVL) &lt;- rownames(anolisData)}}} </td> </tr> </table> </div> III. Loading Character Data into Rhttp://bodegaphylo.wikispot.org/III._Loading_Character_Data_into_R2009-03-09 08:35:45glor <div id="content" class="wikipage content"> Differences for III. Loading Character Data into R<p><strong></strong></p><table> <tr> <td> <span> Deletions are marked with - . </span> </td> <td> <span> Additions are marked with +. </span> </td> </tr> <tr> <td> Line 57: </td> <td> Line 57: </td> </tr> <tr> <td> <span>-</span> Let’s consider the two datasets from Anolis lizards that we’ve already loaded into R, which include a phylogenetic tree ({{{anolisTree}}}) and data on microhabitat specialization and body size ({{{anolisData}}}). To determine which taxa are overlapping in these two files, type: </td> <td> <span>+ '''1.'''</span> Let’s consider the two datasets from Anolis lizards that we’ve already loaded into R, which include a phylogenetic tree ({{{anolisTree}}}) and data on microhabitat specialization and body size ({{{anolisData}}}). To determine which taxa are overlapping in these two files, type: </td> </tr> <tr> <td> Line 63: </td> <td> Line 63: </td> </tr> <tr> <td> <span>-</span> In order to conduct phylogenetic comparative analyses, we want to prune all the taxa from our tree that are not also present among our trait data. To do this we’re going to save the two lists generated by name.check under the name {{{anolisOverlap}}} and then use the names in the {{{$Tree.not.data}}} portion of this object in an application of the drop.tip function: </td> <td> <span>+ '''2.'''</span> In order to conduct phylogenetic comparative analyses, we want to prune all the taxa from our tree that are not also present among our trait data. To do this we’re going to save the two lists generated by name.check under the name {{{anolisOverlap}}} and then use the names in the {{{$Tree.not.data}}} portion of this object in an application of the drop.tip function: </td> </tr> <tr> <td> Line 66: </td> <td> Line 66: </td> </tr> <tr> <td> <span>-</span> &gt;drop.tip(anolisTree, anolisOverlap$Tree.not.data) -&gt; anolisComparativeTree}}} </td> <td> <span>+</span> <span>&nbsp;</span>&gt;drop.tip(anolisTree, anolisOverlap$Tree.not.data) -&gt; anolisComparativeTree}}} </td> </tr> </table> </div> III. Loading Character Data into Rhttp://bodegaphylo.wikispot.org/III._Loading_Character_Data_into_R2009-03-09 08:34:33glor <div id="content" class="wikipage content"> Differences for III. Loading Character Data into R<p><strong></strong></p><table> <tr> <td> <span> Deletions are marked with - . </span> </td> <td> <span> Additions are marked with +. </span> </td> </tr> <tr> <td> Line 51: </td> <td> Line 51: </td> </tr> <tr> <td> <span>- {{{ &gt;names(micro) &lt;- rownames(anolisData)<br> - &gt;names(SVL) &lt;- rownames(anolisData)}}}</span> </td> <td> <span>+ {{{ &gt;names(micro) &lt;- rownames(anolisData)[[br]]&gt;names(SVL) &lt;- rownames(anolisData)}}}<br> + <br> + ==='''B. Checking overlap of phylogenetic and trait datasets'''===<br> + -----<br> + Once you have a tree and associated data in R you're well positioned to conduct a phylogenetic comparative analysis. Before doing this however we need to make sure that we have overlapping phylogenetic and character data. The R package {{{Geiger}}} includes a function called {{{name.check}}} that makes it relatively easy to (1) check for overlap between the taxa in a phylogenetic trees and the taxa for which you have some other sort of character data, and (2) prune taxa missing from your tree or trait data in subsequent analyses.<br> + <br> + Let’s consider the two datasets from Anolis lizards that we’ve already loaded into R, which include a phylogenetic tree ({{{anolisTree}}}) and data on microhabitat specialization and body size ({{{anolisData}}}). To determine which taxa are overlapping in these two files, type:<br> + <br> + {{{ &gt;name.check(anolisTree, anolisData)}}}<br> + <br> + The output should consist of two lists of taxon names, one called {{{$Tree.not.data}}} and another called {{{$Data.not.tree}}}. In our case, the fact that numerous names are present in the {{{$Tree.not.data}}} list means that some anole species are represented in our tree, but not in our set of character data (the reason for this is that our tree was reconstructed using anoles from across the genus, whereas character data was only available for species from the Greater Antilles whose microhabitat specialization has been characterized). By contrast, the {{{$Data.not.tree}}} list should be empty (indicated by {{{character(0))}}}, suggesting that there are no taxa in our comparative dataset that are absent from the tree.<br> + <br> + In order to conduct phylogenetic comparative analyses, we want to prune all the taxa from our tree that are not also present among our trait data. To do this we’re going to save the two lists generated by name.check under the name {{{anolisOverlap}}} and then use the names in the {{{$Tree.not.data}}} portion of this object in an application of the drop.tip function:<br> + <br> + {{{ &gt;name.check(anolisTree, anolisData) -&gt; anolisOverlap<br> + &gt;drop.tip(anolisTree, anolisOverlap$Tree.not.data) -&gt; anolisComparativeTree}}}<br> + <br> + Take a look at your newly pruned tree by typing {{{plot(anolisComparativeTree)}}}.</span> </td> </tr> </table> </div> III. Loading Character Data into Rhttp://bodegaphylo.wikispot.org/III._Loading_Character_Data_into_R2009-03-09 08:24:21glor <div id="content" class="wikipage content"> Differences for III. Loading Character Data into R<p><strong></strong></p><table> <tr> <td> <span> Deletions are marked with - . </span> </td> <td> <span> Additions are marked with +. </span> </td> </tr> <tr> <td> Line 13: </td> <td> Line 13: </td> </tr> <tr> <td> <span>-</span> ===Introduction=== </td> <td> <span>+</span> ===<span>'''</span>Introduction<span>'''</span>=== </td> </tr> <tr> <td> Line 17: </td> <td> Line 17: </td> </tr> <tr> <td> <span>-</span> ===A. Loading trait data into R=== </td> <td> <span>+</span> ===<span>'''</span>A. Loading trait data into R<span>'''</span>=== </td> </tr> <tr> <td> Line 31: </td> <td> Line 31: </td> </tr> <tr> <td> <span>-</span> '''a''' We now need to perform a few basic functions that will make our data easier to work with in R’s framework. First, we’re going to convert the table into a dataframe. A dataframe is an R format that breaks a matrix down so that each column is represented as a distinct object in R’s working environment. We want the columns of our dataframe to consist solely of our ecological and morphological character data - the taxon names in the first column of our .csv file will be stored as another component of our dataframe in just a moment. To get our two columns of character data (columns 2 and 3 of our original .csv file) into a dataframe we simply type: </td> <td> <span>+</span> '''a<span>.</span>''' We now need to perform a few basic functions that will make our data easier to work with in R’s framework. First, we’re going to convert the table into a dataframe. A dataframe is an R format that breaks a matrix down so that each column is represented as a distinct object in R’s working environment. We want the columns of our dataframe to consist solely of our ecological and morphological character data - the taxon names in the first column of our .csv file will be stored as another component of our dataframe in just a moment. To get our two columns of character data (columns 2 and 3 of our original .csv file) into a dataframe we simply type: </td> </tr> <tr> <td> Line 37: </td> <td> Line 37: </td> </tr> <tr> <td> <span>-</span> b. Now let’s add names to the rows in our dataframe by telling R that these names can be found in the first column of anolis.dat. </td> <td> <span>+</span> <span>'''</span>b.<span>'''</span> Now let’s add names to the rows in our dataframe by telling R that these names can be found in the first column of anolis.dat. </td> </tr> <tr> <td> Line 43: </td> <td> Line 43: </td> </tr> <tr> <td> <span>-</span> <span>c.</span> Next we’re going to make our dataframe the default dataframe in R’s system by using the attach function. This will allow us to call elements of the dataframe without constantly making reference to the name of the dataframe itself. Before using the attach command, try typing the name of one of the columns of your dataframe (e.g., micro). You should end up with an error message. Now attach your dataframe by typing: </td> <td> <span>+</span> <span>'''c.'''</span> Next we’re going to make our dataframe the default dataframe in R’s system by using the attach function. This will allow us to call elements of the dataframe without constantly making reference to the name of the dataframe itself. Before using the attach command, try typing the name of one of the columns of your dataframe (e.g., micro). You should end up with an error message. Now attach your dataframe by typing: </td> </tr> <tr> <td> Line 49: </td> <td> Line 49: </td> </tr> <tr> <td> <span>-</span> d. To make things even easier for subsequent analyses, we're going to reapply taxon names to the microhabitat and body size data. </td> <td> <span>+</span> <span>'''</span>d.<span>'''</span> To make things even easier for subsequent analyses, we're going to reapply taxon names to the microhabitat and body size data. </td> </tr> <tr> <td> Line 52: </td> <td> Line 52: </td> </tr> <tr> <td> <span>-</span> <span>&nbsp;&nbsp;</span>&gt;names(SVL) &lt;- rownames(anolisData)}}} </td> <td> <span>+</span> &gt;names(SVL) &lt;- rownames(anolisData)}}} </td> </tr> </table> </div> III. Loading Character Data into Rhttp://bodegaphylo.wikispot.org/III._Loading_Character_Data_into_R2009-03-09 08:23:22glor <div id="content" class="wikipage content"> Differences for III. Loading Character Data into R<p><strong></strong></p><table> <tr> <td> <span> Deletions are marked with - . </span> </td> <td> <span> Additions are marked with +. </span> </td> </tr> <tr> <td> Line 31: </td> <td> Line 31: </td> </tr> <tr> <td> <span>- </span>'''<span>3</span>''' We now need to perform a few basic functions that will make our data easier to work with in R’s framework. First, we’re going to convert the table into a dataframe. A dataframe is an R format that breaks a matrix down so that each column is represented as a distinct object in R’s working environment. We want the columns of our dataframe to consist solely of our ecological and morphological character data - the taxon names in the first column of our .csv file will be stored as another component of our dataframe in just a moment. To get our two columns of character data (columns 2 and 3 of our original .csv file) into a dataframe we simply type: </td> <td> <span>+ </span>'''<span>a</span>''' We now need to perform a few basic functions that will make our data easier to work with in R’s framework. First, we’re going to convert the table into a dataframe. A dataframe is an R format that breaks a matrix down so that each column is represented as a distinct object in R’s working environment. We want the columns of our dataframe to consist solely of our ecological and morphological character data - the taxon names in the first column of our .csv file will be stored as another component of our dataframe in just a moment. To get our two columns of character data (columns 2 and 3 of our original .csv file) into a dataframe we simply type: </td> </tr> <tr> <td> Line 33: </td> <td> Line 33: </td> </tr> <tr> <td> <span>-</span> {{{ &gt;data.frame(anolis.dat[,2:3]) -&gt; anolisData}}} </td> <td> <span>+</span> {{{<span>&nbsp;</span> &gt;data.frame(anolis.dat[,2:3]) -&gt; anolisData}}} </td> </tr> <tr> <td> Line 35: </td> <td> Line 35: </td> </tr> <tr> <td> <span>- </span>This should convert the second and third columns of {{{anolis.dat}}} into a dataframe called {{{anolisData}}}. It is critically important that you begin to understand how and why the square brackets are being used after {{{anolis.dat}}} in this line: this is another case where the square brackets are being used to indicate specific elements of an R object (recall our use of double square brackets to indicate that we wanted only one of the two trees in our MrBayes {{{.con}}} file). When we have a matrix with multiple rows and columns, specific elements of this matrix are indicated by enclosing the specific rows and columns in square brackets separated by a comma (e.g., {{{[rows,columns]}}}). If we leave the area for rows or columns blank, all rows or columns will be selected. {{{anolis.dat[1,]}}} for example, will recover the data in row 1 across the three columns in our table. See what happens when you type {{{anolis.dat[1,]}}}. If we want to obtain multiple rows or columns, we can use the colon, which tells R we want a series extending from the number before the colon to the number after the colon ({{{1:5}}}, for example, should return the series {{{‘1 2 3 4 5’}}}). Hopefully now it is becoming clear why we’ve typed {{{[,2:3]}}} after {{{anolis .dat}}}. We did this because we want to extract the character data found in each row of colums 2-3. Try typing anolisData followed by return in R - you should see the data included in columns two and three of your .csv file. </td> <td> <span>+ </span>This should convert the second and third columns of {{{anolis.dat}}} into a dataframe called {{{anolisData}}}. It is critically important that you begin to understand how and why the square brackets are being used after {{{anolis.dat}}} in this line: this is another case where the square brackets are being used to indicate specific elements of an R object (recall our use of double square brackets to indicate that we wanted only one of the two trees in our MrBayes {{{.con}}} file). When we have a matrix with multiple rows and columns, specific elements of this matrix are indicated by enclosing the specific rows and columns in square brackets separated by a comma (e.g., {{{[rows,columns]}}}). If we leave the area for rows or columns blank, all rows or columns will be selected. {{{anolis.dat[1,]}}} for example, will recover the data in row 1 across the three columns in our table. See what happens when you type {{{anolis.dat[1,]}}}. If we want to obtain multiple rows or columns, we can use the colon, which tells R we want a series extending from the number before the colon to the number after the colon ({{{1:5}}}, for example, should return the series {{{‘1 2 3 4 5’}}}). Hopefully now it is becoming clear why we’ve typed {{{[,2:3]}}} after {{{anolis .dat}}}. We did this because we want to extract the character data found in each row of colums 2-3. Try typing anolisData followed by return in R - you should see the data included in columns two and three of your .csv file. </td> </tr> <tr> <td> Line 37: </td> <td> Line 37: </td> </tr> <tr> <td> <span>-</span> Now let’s add names to the rows in our dataframe by telling R that these names can be found in the first column of anolis.dat. </td> <td> <span>+ b.</span> Now let’s add names to the rows in our dataframe by telling R that these names can be found in the first column of anolis.dat. </td> </tr> <tr> <td> Line 39: </td> <td> Line 39: </td> </tr> <tr> <td> <span>-</span> {{{ &gt;rownames(anolisData) &lt;- anolis.dat[,1]}}} </td> <td> <span>+</span> <span>&nbsp;</span>{{{ &gt;rownames(anolisData) &lt;- anolis.dat[,1]}}} </td> </tr> <tr> <td> Line 41: </td> <td> Line 41: </td> </tr> <tr> <td> <span>-</span> Type anolisData and hit return to confirm that your rownames have been added. </td> <td> <span>+</span> <span>&nbsp;</span>Type anolisData and hit return to confirm that your rownames have been added. </td> </tr> <tr> <td> Line 43: </td> <td> Line 43: </td> </tr> <tr> <td> <span>- </span> Next we’re going to make our dataframe the default dataframe in R’s system by using the attach function. This will allow us to call elements of the dataframe without constantly making reference to the name of the dataframe itself. Before using the attach command, try typing the name of one of the columns of your dataframe (e.g., micro). You should end up with an error message. Now attach your dataframe by typing: </td> <td> <span>+ c.</span> Next we’re going to make our dataframe the default dataframe in R’s system by using the attach function. This will allow us to call elements of the dataframe without constantly making reference to the name of the dataframe itself. Before using the attach command, try typing the name of one of the columns of your dataframe (e.g., micro). You should end up with an error message. Now attach your dataframe by typing: </td> </tr> <tr> <td> Line 45: </td> <td> Line 45: </td> </tr> <tr> <td> <span>-</span> {{{ &gt;attach(anolisData)}}} </td> <td> <span>+</span> <span>&nbsp;</span>{{{ &gt;attach(anolisData)}}} </td> </tr> <tr> <td> Line 47: </td> <td> Line 47: </td> </tr> <tr> <td> <span>- Now try typing ‘micro’ again. This time you should get a vector listing your microhabitat data.</span> </td> <td> <span>+ Now try typing ‘micro’ again. This time you should get a vector listing your microhabitat data.<br> + <br> + d. To make things even easier for subsequent analyses, we're going to reapply taxon names to the microhabitat and body size data.<br> + <br> + {{{ &gt;names(micro) &lt;- rownames(anolisData)<br> + &gt;names(SVL) &lt;- rownames(anolisData)}}}</span> </td> </tr> </table> </div> III. Loading Character Data into Rhttp://bodegaphylo.wikispot.org/III._Loading_Character_Data_into_R2009-03-09 08:20:53glor <div id="content" class="wikipage content"> Differences for III. Loading Character Data into R<p><strong></strong></p><table> <tr> <td> <span> Deletions are marked with - . </span> </td> <td> <span> Additions are marked with +. </span> </td> </tr> <tr> <td> Line 20: </td> <td> Line 20: </td> </tr> <tr> <td> <span>- I’ve provided you with a comma-delimited table of data called anolis_data.csv. This file contains ecological and morphological data for Greater Antillean Anolis lizards. This file includes three columns: the first contains species names, the second includes discretely coded information about anole microhabitat specialization (0=grass-bush, 1=trunk-ground, 2=trunk, 3=trunk-crown, 4=crown-giant, 5=twig), and the third contains continuously-coded data on adult body size of adult males (measured as the snout to vent length, or SVL).</span> </td> <td> </td> </tr> <tr> <td> Line 22: </td> <td> Line 21: </td> </tr> <tr> <td> <span>- '''1.''' Start by opening the anolis_data.csv file in EXCEL to see what you’re dealing with.</span> </td> <td> <span>+ I’ve provided you with a comma-delimited table of data called {{{anolis_data.csv}}}. This file contains ecological and morphological data for Greater Antillean Anolis lizards. This file includes three columns: the first contains species names, the second includes discretely coded information about anole microhabitat specialization (0=grass-bush, 1=trunk-ground, 2=trunk, 3=trunk-crown, 4=crown-giant, 5=twig), and the third contains continuously-coded data on adult body size of adult males (measured as the snout to vent length, or SVL).<br> + <br> + '''1.''' Start by opening the {{{anolis_data.csv}}} file in EXCEL to see what you’re dealing with.</span> </td> </tr> <tr> <td> Line 26: </td> <td> Line 27: </td> </tr> <tr> <td> <span>-</span> {{{&gt;read.csv(“anolis_data.csv”) -&gt; anolis.dat </td> <td> <span>+</span> {{{<span>&nbsp;</span>&gt;read.csv(“anolis_data.csv”) -&gt; anolis.dat<span>}}}</span> </td> </tr> <tr> <td> Line 28: </td> <td> Line 29: </td> </tr> <tr> <td> <span>-</span> You can see if all has gone well by typing anolis.dat and hitting return. You should see your data scrolling across the screen. </td> <td> <span>+</span> You can see if all has gone well by typing <span>{{{</span>anolis.dat<span>}}}</span> and hitting return. You should see your data scrolling across the screen. </td> </tr> <tr> <td> Line 30: </td> <td> Line 31: </td> </tr> <tr> <td> <span>-</span> We now need to perform a few basic functions that will make our data easier to work with in R’s framework. First, we’re going to convert the table into a dataframe. A dataframe is an R format that breaks a matrix down so that each column is represented as a distinct object in R’s working environment. We want the columns of our dataframe to consist solely of our ecological and morphological character data - the taxon names in the first column of our .csv file will be stored as another component of our dataframe in just a moment. To get our two columns of character data (columns 2 and 3 of our original .csv file) into a dataframe we simply type: </td> <td> <span>+ '''3'''</span> We now need to perform a few basic functions that will make our data easier to work with in R’s framework. First, we’re going to convert the table into a dataframe. A dataframe is an R format that breaks a matrix down so that each column is represented as a distinct object in R’s working environment. We want the columns of our dataframe to consist solely of our ecological and morphological character data - the taxon names in the first column of our .csv file will be stored as another component of our dataframe in just a moment. To get our two columns of character data (columns 2 and 3 of our original .csv file) into a dataframe we simply type: </td> </tr> <tr> <td> Line 32: </td> <td> Line 33: </td> </tr> <tr> <td> <span>-</span> &gt;data.frame(anolis.dat[,2:3]) -&gt; anolisData </td> <td> <span>+</span> <span>{{{ </span>&gt;data.frame(anolis.dat[,2:3]) -&gt; anolisData<span>}}}</span> </td> </tr> <tr> <td> Line 34: </td> <td> Line 35: </td> </tr> <tr> <td> <span>-</span> This should convert the second and third columns of <span>anolis.dat into a dataframe called </span>anolisData. It is critically important that you begin to understand how and why the square brackets are being used after <span>anolis.dat</span> in this line: this is another case where the square brackets are being used to indicate specific elements of an R object (recall our use of double square brackets to indicate that we wanted only one of the two trees in our MrBayes <span>.con</span> file). When we have a matrix with multiple rows and columns, specific elements of this matrix are indicated by enclosing the specific rows and columns in square brackets separated by a comma (e.g., [rows,columns]). If we leave the area for rows or columns blank, all rows or columns will be selected. anolis.dat[1,] for example, will recover the data in row 1 across the three columns in our table. See what happens when you type anolis.dat[1,]. If we want to obtain multiple rows or columns, we can use the colon, which tells R we want a series extending from the number before the colon to the number after the colon (1:5, for example, should return the series ‘1 2 3 4 5’). Hopefully now it is becoming clear why we’ve typed [,2:3]<span>&nbsp;after anolis .dat</span>. We did this because we want to extract the character data found in each row of colums 2-3. Try typing anolisData followed by return in R - you should see the data included in columns two and three of your .csv file. </td> <td> <span>+</span> This should convert the second and third columns of <span>{{{anolis.dat}}} into a dataframe called {{{</span>anolisData<span>}}}</span>. It is critically important that you begin to understand how and why the square brackets are being used after <span>{{{anolis.dat}}}</span> in this line: this is another case where the square brackets are being used to indicate specific elements of an R object (recall our use of double square brackets to indicate that we wanted only one of the two trees in our MrBayes <span>{{{.con}}}</span> file). When we have a matrix with multiple rows and columns, specific elements of this matrix are indicated by enclosing the specific rows and columns in square brackets separated by a comma (e.g., <span>{{{</span>[rows,columns]<span>}}}</span>). If we leave the area for rows or columns blank, all rows or columns will be selected. <span>{{{</span>anolis.dat[1,]<span>}}}</span> for example, will recover the data in row 1 across the three columns in our table. See what happens when you type <span>{{{</span>anolis.dat[1,]<span>}}}</span>. If we want to obtain multiple rows or columns, we can use the colon, which tells R we want a series extending from the number before the colon to the number after the colon (<span>{{{</span>1:5<span>}}}</span>, for example, should return the series <span>{{{</span>‘1 2 3 4 5’<span>}}}</span>). Hopefully now it is becoming clear why we’ve typed <span>{{{</span>[,2:3]<span>}}} after {{{anolis .dat}}}</span>. We did this because we want to extract the character data found in each row of colums 2-3. Try typing anolisData followed by return in R - you should see the data included in columns two and three of your .csv file. </td> </tr> <tr> <td> Line 38: </td> <td> Line 39: </td> </tr> <tr> <td> <span>-</span> &gt;rownames(anolisData) &lt;- anolis.dat[,1] </td> <td> <span>+</span> <span>{{{</span> &gt;rownames(anolisData) &lt;- anolis.dat[,1]<span>}}}</span> </td> </tr> <tr> <td> Line 44: </td> <td> Line 45: </td> </tr> <tr> <td> <span>-</span> &gt;attach(anolisData) </td> <td> <span>+</span> <span>{{{</span> &gt;attach(anolisData)<span>}}}</span> </td> </tr> </table> </div> III. Loading Character Data into Rhttp://bodegaphylo.wikispot.org/III._Loading_Character_Data_into_R2009-03-09 08:15:50glor <div id="content" class="wikipage content"> Differences for III. Loading Character Data into R<p><strong></strong></p><table> <tr> <td> <span> Deletions are marked with - . </span> </td> <td> <span> Additions are marked with +. </span> </td> </tr> <tr> <td> Line 11: </td> <td> Line 11: </td> </tr> <tr> <td> <span>-</span> ||R for Phylogenetics parts ["I. Getting Started with R" I] and ["II. Tree Basics" II] </td> <td> <span>+</span> ||R for Phylogenetics parts ["I. Getting Started with R" I] and ["II. Tree Basics" II]<span>||</span> </td> </tr> </table> </div> III. Loading Character Data into Rhttp://bodegaphylo.wikispot.org/III._Loading_Character_Data_into_R2009-03-09 08:15:35glor <div id="content" class="wikipage content"> Differences for III. Loading Character Data into R<p><strong></strong></p><table> <tr> <td> <span> Deletions are marked with - . </span> </td> <td> <span> Additions are marked with +. </span> </td> </tr> <tr> <td> Line 10: </td> <td> Line 10: </td> </tr> <tr> <td> <span>-</span> <span><br> - -----<br> - Th</span>is<span>&nbsp;exerc</span>i<span>se assum</span>es <span>t</span>h<span>at </span>yo<span>u hav</span>e<span>&nbsp;already compl</span>et<span>ed</span> parts ["I. Getting Started with R" I] and ["II. Tree Basics" II]<span>.<br> - -----</span> </td> <td> <span>+</span> <span>||&lt;bgcolor='#E0E0FF'&gt;'''Prerequ</span>isi<span>t</span>es<span>'''||<br> +</span> <span>||R for P</span>hy<span>l</span>o<span>g</span>e<span>n</span>et<span>ics</span> parts ["I. Getting Started with R" I] and ["II. Tree Basics" II] </td> </tr> </table> </div> III. Loading Character Data into Rhttp://bodegaphylo.wikispot.org/III._Loading_Character_Data_into_R2009-03-09 08:14:36glor <div id="content" class="wikipage content"> Differences for III. Loading Character Data into R<p><strong></strong></p><table> <tr> <td> <span> Deletions are marked with - . </span> </td> <td> <span> Additions are marked with +. </span> </td> </tr> <tr> <td> Line 1: </td> <td> Line 1: </td> </tr> <tr> <td> </td> <td> <span>+ ||&lt;bgcolor='#E0E0FF'&gt;'''Primary Contact(s)'''||<br> + ||["Users/glor" Rich Glor]||<br> + ||&lt;bgcolor='#E0E0FF'&gt;'''Created'''||<br> + ||7 March 2009||<br> + ||&lt;bgcolor='#E0E0FF'&gt;'''Required Software'''||<br> + ||[http://cran.r-project.org/ R]||<br> + ||&lt;bgcolor='#E0E0FF'&gt;'''Example Datafile'''||<br> + ||[[File(anolis_mtDNA.mrb.con)]]||<br> + ||[[File(anolis_data.csv)]]||<br> + <br> + -----<br> + This exercise assumes that you have already completed parts ["I. Getting Started with R" I] and ["II. Tree Basics" II].<br> + -----<br> + <br> + ===Introduction===<br> + -----</span> </td> </tr> <tr> <td> Line 4: </td> <td> Line 20: </td> </tr> <tr> <td> </td> <td> <span>+ -----</span> </td> </tr> </table> </div> III. Loading Character Data into Rhttp://bodegaphylo.wikispot.org/III._Loading_Character_Data_into_R2009-03-08 14:46:31glor <div id="content" class="wikipage content"> Differences for III. Loading Character Data into R<p><strong></strong></p><table> <tr> <td> <span> Deletions are marked with - . </span> </td> <td> <span> Additions are marked with +. </span> </td> </tr> <tr> <td> Line 1: </td> <td> Line 1: </td> </tr> <tr> <td> </td> <td> <span>+ R is becoming increasingly important to implementation of phylogenetic comparative analyses. Many new methods are developed specifically for the R platform while many older methods are being translated into R packages. We’re going to tackle comparative analyses in R in several stages. Through the course of this exercise we’ll learn how to (1) load comparative data into R, (2) ensure that our comparative data and tree are compatible, (3) conduct basic diagnostic tests of phylogenetic signal, and (4) conduct a variety of standard phylogenetic comparative analyses.<br> + <br> + ===A. Loading trait data into R===<br> + If you have some character data for the species in your phylogeny, you can easily upload and analyze this data in R. Perhaps the easiest way to get your data into R is to start with a simple comma delimited table. You can generate such a table in EXCEL by saving your EXCEL worksheet as a .csv file using the Save As function under the File menu in EXCEL.<br> + I’ve provided you with a comma-delimited table of data called anolis_data.csv. This file contains ecological and morphological data for Greater Antillean Anolis lizards. This file includes three columns: the first contains species names, the second includes discretely coded information about anole microhabitat specialization (0=grass-bush, 1=trunk-ground, 2=trunk, 3=trunk-crown, 4=crown-giant, 5=twig), and the third contains continuously-coded data on adult body size of adult males (measured as the snout to vent length, or SVL).<br> + <br> + '''1.''' Start by opening the anolis_data.csv file in EXCEL to see what you’re dealing with.<br> + <br> + '''2.''' Now let’s open this same file in R using the read.csv function included in R’s base installation:<br> + <br> + {{{&gt;read.csv(“anolis_data.csv”) -&gt; anolis.dat<br> + <br> + You can see if all has gone well by typing anolis.dat and hitting return. You should see your data scrolling across the screen.<br> + <br> + We now need to perform a few basic functions that will make our data easier to work with in R’s framework. First, we’re going to convert the table into a dataframe. A dataframe is an R format that breaks a matrix down so that each column is represented as a distinct object in R’s working environment. We want the columns of our dataframe to consist solely of our ecological and morphological character data - the taxon names in the first column of our .csv file will be stored as another component of our dataframe in just a moment. To get our two columns of character data (columns 2 and 3 of our original .csv file) into a dataframe we simply type:<br> + <br> + &gt;data.frame(anolis.dat[,2:3]) -&gt; anolisData<br> + <br> + This should convert the second and third columns of anolis.dat into a dataframe called anolisData. It is critically important that you begin to understand how and why the square brackets are being used after anolis.dat in this line: this is another case where the square brackets are being used to indicate specific elements of an R object (recall our use of double square brackets to indicate that we wanted only one of the two trees in our MrBayes .con file). When we have a matrix with multiple rows and columns, specific elements of this matrix are indicated by enclosing the specific rows and columns in square brackets separated by a comma (e.g., [rows,columns]). If we leave the area for rows or columns blank, all rows or columns will be selected. anolis.dat[1,] for example, will recover the data in row 1 across the three columns in our table. See what happens when you type anolis.dat[1,]. If we want to obtain multiple rows or columns, we can use the colon, which tells R we want a series extending from the number before the colon to the number after the colon (1:5, for example, should return the series ‘1 2 3 4 5’). Hopefully now it is becoming clear why we’ve typed [,2:3] after anolis .dat. We did this because we want to extract the character data found in each row of colums 2-3. Try typing anolisData followed by return in R - you should see the data included in columns two and three of your .csv file.<br> + <br> + Now let’s add names to the rows in our dataframe by telling R that these names can be found in the first column of anolis.dat.<br> + <br> + &gt;rownames(anolisData) &lt;- anolis.dat[,1]<br> + <br> + Type anolisData and hit return to confirm that your rownames have been added.<br> + <br> + Next we’re going to make our dataframe the default dataframe in R’s system by using the attach function. This will allow us to call elements of the dataframe without constantly making reference to the name of the dataframe itself. Before using the attach command, try typing the name of one of the columns of your dataframe (e.g., micro). You should end up with an error message. Now attach your dataframe by typing:<br> + <br> + &gt;attach(anolisData)<br> + <br> + Now try typing ‘micro’ again. This time you should get a vector listing your microhabitat data.</span> </td> </tr> </table> </div>