To accomplish this, I have just added one additional argument:
> args(phenogram)
function (tree, x, fsize = 1, ftype = "reg", colors = NULL, axes = list())
NULL
This is specified as a list containing two components: trait and time. The former should be a vector of length 2 specifying the dimensions of the vertical (trait) axis; and the latter a vector of length 2 giving the desired dimensions on the horizontal (time since the root) axis.
Within the function itself, I have now added the following lines of code (before calling plot.window to create the graph):
plot.new()
if(is.null(axes$trait)) ylim<-c(min(x),max(x))
else ylim<-axes$trait
if(is.null(axes$time))
xlim<-c(min(H),max(H)+fsize*max(strwidth(tree$tip.label)))
else
xlim<-c(axes$time[1],axes$time[2]+fsize*max(strwidth(tree$tip.label)))
plot.window(ylim=ylim,xlim=xlim)
This code just uses the vectors provide in axes to specify the dimensions in x & y for the plot - or, if none have been provided, it uses the range of x and nodeHeights(tree) (plus a little bit of extra space to print tip labels).
Let's see how it works:
> source("phenogram.R")
> tree<-pbtree(n=10)
> x<-fastBM(tree)
> phenogram(tree,x) # default settings
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhgH3MKqL5wqYeKGXW5A5nPk4CCcldzrlfQTtFZpl2jyh8A6-GfkE7GF9HSdT6O4dyglEdgnPm224L2bBJMXsn0Ro9cd6kBcMY-89FyVEEKvYS5LiE7vK2v7zkSlzqeVJzdoarK12G1VNzG/s400/phenogram3.png)
> phenogram(tree,x,axes=list(trait=c(-2,2))) # change vertical
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjSlF0SQaRurHn8gYASdY3skKvi_7xvRg7H0r95AQenko1epr0VyrsBDOmPS61XOSZKH4qBBta92KeuL2s_y7jwd6kXCazNlA1wWPKOfKG-FBtmVpX5YRVHMraT3hA0lLr9r5BcoWCQFPJF/s400/phenogram4.png)
> # change horizontal
> phenogram(tree,x,axes=list(trait=c(-2,2), time=c(1.5,max(nodeHeights(tree)))))
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg8bLWo1fy0Pxia-HqWgwWPLPqW0rJ4bV1NDIEjU7Tif4aE1wGiK6JsAOulVrNGoFtrwaWhiYbyCkXJlyMfwX8SPHyibZNiSVBlZwHSgDX884wEYuin9qywjst1fswCRfwDhLWd6y_IPUVc/s400/phenogram5.png)
It also works with a mapped discrete character. For instance:
> Q<-matrix(c(-2,2,2,-2),2,2)
> mtree<-sim.history(tree,Q)
> cols<-c("blue","red"); names(cols)<-c(1,2)
> phenogram(mtree,x,colors=cols,axes=list(trait=c(-2,2)))
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhnVxF5bKYwfM4IA65KELyG2_yenuwFUT8ZifkY1HEKoVZxCprm6Qsiiey_679XJEk0YS-PsNJaiauIxRnofgM2IwGYAdRHBsz8RJgHq6QiPb6bioUEXBiBs33vtYFaRCOerIezzfeUUf61/s400/phenogram6.png)
Cool.
Thanks!
ReplyDelete