Skip to content

Commit

Permalink
improved bimaculatus data; example of plotting long taxon names
Browse files Browse the repository at this point in the history
  • Loading branch information
kingaa committed May 9, 2021
1 parent 48405c4 commit 301e8b9
Show file tree
Hide file tree
Showing 25 changed files with 186 additions and 116 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Package: ouch
Type: Package
Title: Ornstein-Uhlenbeck Models for Phylogenetic Comparative Hypotheses
Version: 2.16-5
Date: 2021-05-06
Version: 2.16-7
Date: 2021-05-09
Authors@R: c(person(given=c("Aaron","A."),family="King",role=c("aut","cre"),email="kingaa@umich.edu"),
person(given=c("Marguerite","A."),family="Butler",role=c("ctb")))
Maintainer: Aaron A. King <kingaa@umich.edu>
Expand Down
6 changes: 3 additions & 3 deletions R/anolis.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
#' Size dimorphism was calcuated as the log-ratio of male snout-to-vent length to female snout-to-vent length (males are larger).
#'
#' In this example, we tested three models of evolution:
#' Brownian motion, Ornstein-Uhlenbeck with one global optimum, and Ornstein-Uhlenbeck with 7 optima (one for each ecomorph type plus an additional one for an "unknown" type).
#' Brownian motion, Ornstein-Uhlenbeck with one global optimum, and Ornstein-Uhlenbeck with seven optima (one for each ecomorph type plus an additional one for an "unknown" type).
#'
#' For the 7-optima model, we assigned each terminal branch to an optimum according to the ecomorph type of the extant species.
#' For the seven-optima model, we assigned each terminal branch to an optimum according to the ecomorph type of the extant species.
#' Because we had no information to help guide hypotheses about internal branches, we assigned
#' internal branches to the "unknown" selective regime.
#' The phylogeny of these species is consistent with and adaptive radiation, with a burst of speciation events early in the evolutionary history of this clade (see phylogeny in Butler & King (2004) or example below).
Expand All @@ -24,7 +24,7 @@
#' - `node`: Labels for the nodes.
#' - `species`: Names of extant species.
#' - `log.SSD`: Log sexual size dimorphism of extant species.
#' - `ancestor`: Ancestor node.
#' - `ancestor`: Name of ancestor node.
#' - `time`: Time of node.
#' - `OU.1`: a factor with one level, `ns`.
#' - `OU.7`: a factor with levels corresponding to ecomorph (`tg`, `tc`, `gb`, `cg`, `tw`, `tr`, `anc`).
Expand Down
25 changes: 15 additions & 10 deletions R/bimac.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#' The data frame has the following columns:
#' `species` which are species names,
#' `size` which is the phenotypic data,
#' and the variables `ancestor` and `time` which specify the topology of the phylogeny and the location of the nodes in time, respectively.
#' and the variables `node`, `ancestor`, and `time` which specify the topology of the phylogeny and the location of the nodes in time, respectively.
#' The columns `OU.1`, `OU.3`, `OU.4`, and `OU.LP` specify four hypothetical arrangements of selective regimes.
#' Explanations of the data follow:
#' \describe{
Expand All @@ -14,31 +14,36 @@
#' In this group of lizards, head length correlates very strongly with snout-to-vent length and the cube root of mass, which are standard measures of body size.
#' The data are head lengths in mm; note that we use the log of this value in analyses.
#' }
#' \item{Tree topology}{
#' The tree topology is encoded via two vectors: `ancestor` and `time`.
#' Each node of the' phylogenetic tree has a corresponding row in the data frame, numbered from 1 to 45.
#' The columns `ancestor` and `time` specify the phylogeny.
#' The `ancestor` variable specifies the topology: it is a list indicating the ancestor of each node.
#' The root node has ancestor 0.
#' The variable `time` specifies the temporal location of each node, with the root node being at time 0.
#' \item{Tree structure}{
#' The phylogenetic tree is encoded via three variables:
#' `node`, `ancestor`, and `time`.
#' The `node` variable gives a name to each node.
#' The `ancestor` variable names the ancestor of each node.
#' The root node has no ancestor (i.e., \code{ancestor=NA}).
#' The variable `time` specifies the temporal location of each node, the root node being at time 0.
#' }
#' \item{Specifications of selective regimes.}{
#' (Columns `OU.1`, `OU.3`, `OU.4`, `OU.LP`).
#' These columns are factors, the levels of which correspond to the "paintings" of the respective adaptive regime hypotheses onto the phylogeny (see [paint()]).
#' These columns are factors, the levels of which correspond to the \dQuote{paintings} of the respective adaptive regime hypotheses onto the phylogeny (see [paint()]).
#' Each selective regime is named (small, medium, large, etc.).
#' Each column corresponds to a different painting of the selective regimes, and thus to a different hypothesis.
#' In this example, there are 3 alternative models (see Butler & King 2004): `OU.4` is 4-regime model, `OU.3` is 3-regime model (all ancestors are medium), `OU.LP` is the linear parsimony model.
#' }
#' \item{Other variables}{
#' In addition to the above, there is a two-letter code for each taxon (`spcode`) and the name of the island on which the taxon is found (`island`).
#' }
#' }
#'
#' @name bimac
#' @rdname bimac
#' @docType data
#' @family examples
#' @format A data frame with 45 observations on the following 8 variables.
#' @format A data frame with 45 observations on the following 11 variables.
#' \describe{
#' \item{node}{Labels for the nodes.}
#' \item{spcode}{Two-letter code for each taxon.}
#' \item{species}{Species names for extant species.}
#' \item{island}{Name of the island on which the population is found.}
#' \item{size}{Body size (head length in mm) of extant species.}
#' \item{ancestor}{Ancestral node.}
#' \item{time}{Time of node.}
Expand Down
4 changes: 2 additions & 2 deletions R/plot.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#' There must be at least as many colors as levels in the `regimes`.
#' @param labels character; taxon labels.
#' @param margin numeric; width of the right margin (as a fraction of the plot width).
#' Adjust this if labels are clipped.
#' Adjust this if labels are clipped (see Examples below).
#' @param text_opts options for the labels; passed to [`text`][graphics::text()].
#' @param legend_opts options for the the legend; passed to [`legend`][graphics::legend()].
#' @param ... additional arguments, passed to [`plot`][graphics::plot()].
Expand Down Expand Up @@ -47,7 +47,7 @@ tree.plot.internal <- function (
rx <- range(x@times,na.rm=T)
margin <- as.numeric(margin)
if (!(length(margin)==1 && isTRUE(margin>=0 && margin<1)))
pStop("plot",sQuote("margin")," should be between 0 and 1.")
pStop("plot",sQuote("margin")," should be one number between 0 and 1.")
rxd <- margin*diff(rx)/(1-margin)
anc <- x@anc.numbers
root <- which(is.root.node(anc))
Expand Down
92 changes: 46 additions & 46 deletions data/bimac.csv
Original file line number Diff line number Diff line change
@@ -1,46 +1,46 @@
node;species;size;ancestor;time;OU.1;OU.3;OU.4;OU.LP
1;NA;NA;NA;0;ns;medium;anc;medium
2;NA;NA;1;12;ns;medium;anc;medium
3;NA;NA;2;32;ns;medium;anc;small
4;NA;NA;3;34;ns;medium;anc;small
5;NA;NA;4;36;ns;medium;anc;small
6;NA;NA;3;36;ns;medium;anc;small
7;NA;NA;1;8;ns;medium;anc;medium
8;NA;NA;7;13;ns;medium;anc;medium
9;NA;NA;8;18;ns;medium;anc;large
10;NA;NA;9;23;ns;medium;anc;large
11;NA;NA;10;28;ns;medium;anc;large
12;NA;NA;9;28;ns;medium;anc;large
13;NA;NA;8;22;ns;medium;anc;medium
14;NA;NA;13;26;ns;medium;anc;medium
15;NA;NA;14;34;ns;medium;anc;medium
16;NA;NA;15;36;ns;medium;anc;medium
17;NA;NA;7;28;ns;medium;anc;medium
18;NA;NA;17;30;ns;medium;anc;medium
19;NA;NA;18;34;ns;medium;anc;medium
20;NA;NA;19;36;ns;medium;anc;medium
21;NA;NA;20;37;ns;medium;anc;medium
22;NA;NA;19;36;ns;medium;anc;medium
23;po;13.5;2;38;ns;small;small;small
24;se;14.3;4;38;ns;small;small;small
25;sc;14.3;5;38;ns;small;small;small
26;sn;14.2;5;38;ns;small;small;small
27;wb;14.5;6;38;ns;small;small;small
28;wa;14.9;6;38;ns;small;small;small
29;be;23.6;10;38;ns;large;large;large
30;bn;27.1;11;38;ns;large;large;large
31;bc;27.9;11;38;ns;large;large;large
32;lb;28.6;12;38;ns;large;large;large
33;la;28.8;12;38;ns;large;large;large
34;nu;21.1;13;38;ns;medium;medium;medium
35;sa;18.3;14;38;ns;medium;medium;medium
36;gb;19.7;15;38;ns;medium;medium;medium
37;ga;18.8;16;38;ns;medium;medium;medium
38;gm;19.6;16;38;ns;large;large;large
39;oc;22.3;17;38;ns;medium;medium;medium
40;fe;28.4;18;38;ns;medium;medium;medium
41;li;18.7;20;38;ns;medium;medium;medium
42;mg;18.9;21;38;ns;medium;medium;medium
43;md;19.9;21;38;ns;medium;medium;medium
44;t1;21.3;22;38;ns;medium;medium;medium
45;t2;21.5;22;38;ns;medium;medium;medium
node;spcode;species;island;size;ancestor;time;OU.1;OU.3;OU.4;OU.LP
1;NA;NA;NA;NA;NA;0;ns;medium;anc;medium
2;NA;NA;NA;NA;1;12;ns;medium;anc;medium
3;NA;NA;NA;NA;2;32;ns;medium;anc;small
4;NA;NA;NA;NA;3;34;ns;medium;anc;small
5;NA;NA;NA;NA;4;36;ns;medium;anc;small
6;NA;NA;NA;NA;3;36;ns;medium;anc;small
7;NA;NA;NA;NA;1;8;ns;medium;anc;medium
8;NA;NA;NA;NA;7;13;ns;medium;anc;medium
9;NA;NA;NA;NA;8;18;ns;medium;anc;large
10;NA;NA;NA;NA;9;23;ns;medium;anc;large
11;NA;NA;NA;NA;10;28;ns;medium;anc;large
12;NA;NA;NA;NA;9;28;ns;medium;anc;large
13;NA;NA;NA;NA;8;22;ns;medium;anc;medium
14;NA;NA;NA;NA;13;26;ns;medium;anc;medium
15;NA;NA;NA;NA;14;34;ns;medium;anc;medium
16;NA;NA;NA;NA;15;36;ns;medium;anc;medium
17;NA;NA;NA;NA;7;28;ns;medium;anc;medium
18;NA;NA;NA;NA;17;30;ns;medium;anc;medium
19;NA;NA;NA;NA;18;34;ns;medium;anc;medium
20;NA;NA;NA;NA;19;36;ns;medium;anc;medium
21;NA;NA;NA;NA;20;37;ns;medium;anc;medium
22;NA;NA;NA;NA;19;36;ns;medium;anc;medium
23;po;Anolis pogus;St. Maarten;13.5;2;38;ns;small;small;small
24;se;Anolis schwartzi;St. Eustasius;14.3;4;38;ns;small;small;small
25;sc;Anolis schwartzi;St. Christopher;14.3;5;38;ns;small;small;small
26;sn;Anolis schwartzi;Nevis;14.2;5;38;ns;small;small;small
27;wb;Anolis wattsii;Barbuda;14.5;6;38;ns;small;small;small
28;wa;Anolis wattsii;Antigua;14.9;6;38;ns;small;small;small
29;be;Anolis bimaculatus;St. Eustasius;23.6;10;38;ns;large;large;large
30;bn;Anolis bimaculatus;Nevis;27.1;11;38;ns;large;large;large
31;bc;Anolis bimaculatus;St. Christopher;27.9;11;38;ns;large;large;large
32;lb;Anolis leachi;Barbuda;28.6;12;38;ns;large;large;large
33;la;Anolis leachi;Antigua;28.8;12;38;ns;large;large;large
34;nu;Anolis nubilus;Redonda;21.1;13;38;ns;medium;medium;medium
35;sa;Anolis sabanus;Saba;18.3;14;38;ns;medium;medium;medium
36;gb;Anolis gingivinus;St. Barthelemy;19.7;15;38;ns;medium;medium;medium
37;ga;Anolis gingivinus;Antigua;18.8;16;38;ns;medium;medium;medium
38;gm;Anolis gingivinus;St. Maarten;19.6;16;38;ns;large;large;large
39;oc;Anolis oculatus;Dominica;22.3;17;38;ns;medium;medium;medium
40;fe;Anolis ferreus;Marie Galante;28.4;18;38;ns;medium;medium;medium
41;li;Anolis lividus;Montserrat;18.7;20;38;ns;medium;medium;medium
42;mg;Anolis marmoratus;Guadeloupe;18.9;21;38;ns;medium;medium;medium
43;md;Anolis marmoratus;Desirade;19.9;21;38;ns;medium;medium;medium
44;t1;Anolis terraealtae;Illes de Saintes-1;21.3;22;38;ns;medium;medium;medium
45;t2;Anolis terraealtae;Illes de Saintes-2;21.5;22;38;ns;medium;medium;medium
3 changes: 2 additions & 1 deletion examples/bimac.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
## Analysis of Anolis bimaculatus data
tree <- with(bimac,ouchtree(node,ancestor,time/max(time),species))
tree <- with(bimac,ouchtree(node,ancestor,time/max(time),spcode))
plot(tree,node.names=TRUE)

h1 <- brown(log(bimac['size']),tree)
Expand All @@ -21,6 +21,7 @@ plot(h4)
h5 <- hansen(log(bimac['size']),tree,bimac['OU.LP'],sqrt.alpha=1,sigma=1,reltol=1e-5)
h5 <- update(h5,method='subplex',reltol=1e-11,parscale=c(0.1,0.1),hessian=TRUE)
h5
plot(h5)

simdat <- simulate(h5,nsim=10)
hsim <- update(h5,data=simdat[[1]])
Expand Down
16 changes: 14 additions & 2 deletions examples/bimac1.R
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
tree <- with(
bimac,
ouchtree(nodes=node,ancestors=ancestor,times=time,labels=species)
ouchtree(nodes=node,ancestors=ancestor,times=time,labels=spcode)
)
tree

plot(tree)
plot(tree,node.names=TRUE)
plot(tree, node.names=TRUE) # display node names

## When taxon names are long, they are cut off when the
## default settings are used. For example:
tree2 <- with(
bimac,
ouchtree(nodes=node,ancestors=ancestor,times=time,
labels=ifelse(is.na(species),NA,paste(species,island,sep=", "))
)
)
plot(tree2) # long species names are cut off
## This is fixed by increasing right margin and font size:
plot(tree2,margin=0.5)
5 changes: 5 additions & 0 deletions inst/NEWS
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
_N_e_w_s _f_o_r _P_a_c_k_a_g_e '_o_u_c_h'

_C_h_a_n_g_e_s _i_n _o_u_c_h _v_e_r_s_i_o_n _2._1_6-_6:

• There is now an example showing how to plot a tree with long
taxon names.

_C_h_a_n_g_e_s _i_n _o_u_c_h _v_e_r_s_i_o_n _2._1_6-_3:

• Error messages and examples have been improved somewhat.
Expand Down
5 changes: 5 additions & 0 deletions inst/NEWS.Rd
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
\name{NEWS}
\title{News for Package 'ouch'}
\section{Changes in ouch version 2.16-6}{
\itemize{
\item There is now an example showing how to plot a tree with long taxon names.
}
}
\section{Changes in ouch version 2.16-3}{
\itemize{
\item Error messages and examples have been improved somewhat.
Expand Down
6 changes: 3 additions & 3 deletions man/anolis_ssd.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 17 additions & 11 deletions man/bimac.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion man/brown.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 14 additions & 2 deletions man/ouchtree.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 301e8b9

Please sign in to comment.