]> git.donarmstrong.com Git - ape.git/blob - R/plot.popsize.R
new option 'rotate.tree' in plot.phylo()
[ape.git] / R / plot.popsize.R
1 ## plot.popsize.R (2004-07-4)
2
3 ##   Plot population size in dependence of time
4
5 ## Copyright 2004 Rainer Opgen-Rhein and Korbinian Strimmer
6
7 ## This file is part of the R-package `ape'.
8 ## See the file ../COPYING for licensing issues.
9
10 plot.popsize <- function(x, show.median=TRUE,
11     show.years=FALSE, subst.rate, present.year, ...)
12 {
13   if (class(x) != "popsize")
14     stop("object \"x\" is not of class \"popsize\"")
15
16   ylim <- c(min(popsize[,2:5]),max(popsize[,2:5]))
17   if (show.years)
18   {
19     x1 <- -x[,1]/subst.rate+present.year
20     xlab <- "time (years)"
21     xlim <- c(min(x1),max(x1))
22   }
23   else
24   {
25     x1 <- x[,1]
26     xlab <- "time (past to present in units of substitutions)"
27     xlim <- c(max(x1),min(x1))
28   }
29
30   if (show.median)
31     plot(x1,x[,3],type="s", xlim=xlim, ylim=ylim, xlab=xlab,ylab="effective population size",log="y", lwd=2.5, ...) #median
32   else
33     plot(x1,x[,2],type="s", xlim=xlim, ylim=ylim, xlab=xlab,ylab="effective population size",log="y", lwd=2.5, ...) #median
34
35   lines(x1,x[,4], ...)
36   lines(x1,x[,5], ...)
37 }
38
39
40
41 lines.popsize <- function(x, show.median=TRUE,
42     show.years=FALSE, subst.rate, present.year, ...)
43 {
44   if (class(x) != "popsize")
45     stop("object \"x\" is not of class \"popsize\"")
46
47   if (show.years)
48   {
49     x1 <- -x[,1]/subst.rate+present.year
50   }
51   else
52   {
53     x1 <- x[,1]
54   }
55
56
57   if (show.median)
58     lines(x1,x[,3], lwd=2.5, ...) #median
59   else
60     lines(x1,x[,2], lwd=2.5, ...) #median
61
62   lines(x1,x[,4], ...)
63   lines(x1,x[,5], ...)
64 }