Skip to content

Commit

Permalink
update to phylo.heatmap to control size of subplots
Browse files Browse the repository at this point in the history
  • Loading branch information
liamrevell committed Feb 3, 2016
1 parent dd37d18 commit 4242df8
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 12 deletions.
8 changes: 4 additions & 4 deletions DESCRIPTION
@@ -1,6 +1,6 @@
Package: phytools
Version: 0.5-14
Date: 2016-1-31
Version: 0.5-15
Date: 2016-2-3
Title: Phylogenetic Tools for Comparative Biology (and Other Things)
Author: Liam J. Revell
Maintainer: Liam J. Revell <liam.revell@umb.edu>
Expand Down Expand Up @@ -53,6 +53,6 @@ Description: Package contains various functions for phylogenetic analysis.
their research.
License: GPL (>= 2)
URL: http://www.phytools.org
Packaged: 2016-1-31 12:00:00 EST
Packaged: 2016-2-3 12:00:00 EST
Repository:
Date/Publication: 2016-1-31 12:00:00 EST
Date/Publication: 2016-2-3 12:00:00 EST
19 changes: 12 additions & 7 deletions R/phylo.heatmap.R
Expand Up @@ -2,19 +2,22 @@
## written by Liam J. Revell 2016

phylo.heatmap<-function(tree,X,fsize=1,colors=NULL,standardize=FALSE,...){
if(length(fsize)!=3) fsize<-rep(fsize[1],3)
if(length(fsize)!=3) fsize<-rep(fsize,3)
if(hasArg(legend)) legend<-list(...)$legend
else legend<-TRUE
if(hasArg(labels)) labels<-list(...)$labels
else labels<-TRUE
if(hasArg(split)) split<-list(...)$split
else split<-c(0.5,0.5)
split<-split/sum(split)
if(is.null(colnames(X))) colnames(X)<-paste("var",1:ncol(X),sep="")
if(standardize){
sd<-apply(X,2,function(x) sqrt(var(x)))
X<-(X-matrix(rep(1,Ntip(tree)),Ntip(tree),1)%*%colMeans(X))/
(matrix(rep(1,Ntip(tree)),Ntip(tree),1)%*%sd)
}
if(hasArg(xlim)) xlim<-list(...)$xlim
else xlim<-c(-0.5,2)
else xlim<-c(-0.5,(2-0.5)*split[2]/split[1]+0.5)
if(hasArg(ylim)) ylim<-list(...)$ylim
else ylim<-if(legend) c(if(standardize) -0.15 else -0.1,
if(labels) 1.1 else 1) else c(0,if(labels) 1.1 else 1)
Expand All @@ -26,18 +29,20 @@ phylo.heatmap<-function(tree,X,fsize=1,colors=NULL,standardize=FALSE,...){
par(mar=mar)
plot.window(xlim=xlim,ylim=ylim)
h<-phylogram(tree,fsize=fsize[1])
START<-h+1/2*(2-h)/(ncol(X)-1)+0.5*strwidth("W")*fsize[1]
END<-2-1/2*(2-START)/(ncol(X)-1)
START<-h+1/2*((2-0.5)*split[2]/split[1]+0.5-h)/(ncol(X)-1)+
0.5*strwidth("W")*fsize[1]
END<-(2-0.5)*split[2]/split[1]+0.5-1/2*((2-0.5)*split[2]/split[1]+
0.5-START)/(ncol(X)-1)
image(x=seq(START,END,by=(END-START)/(ncol(X)-1)),
z=t(X[cw$tip.label,]),add=TRUE,
col=colors,...)
add.color.bar(leg=END-START,cols=colors,lims=range(X),
if(legend) add.color.bar(leg=END-START,cols=colors,lims=range(X),
title=if(standardize) "standardized value" else "value",
subtitle=if(standardize) "SD units" else "",prompt=FALSE,x=START,
y=-1/(2*(Ntip(tree)-1))-2*fsize[3]*strheight("W"),
y=-1/(2*(Ntip(tree)-1))-3*fsize[3]*strheight("W"),
digits=if(max(abs(X))<1) round(log10(1/max(abs(X))))+1 else 2,
fsize=fsize[3])
text(x=seq(START,END,by=(END-START)/(ncol(X)-1)),
if(labels) text(x=seq(START,END,by=(END-START)/(ncol(X)-1)),
y=rep(1+1/(2*(Ntip(tree)-1))+0.4*fsize[2]*strwidth("I"),ncol(X)),
colnames(X),srt=70,adj=c(0,0.5),cex=fsize[2])
}
2 changes: 1 addition & 1 deletion man/phylo.heatmap.Rd
Expand Up @@ -10,7 +10,7 @@ phylo.heatmap(tree, X, fsize=1, colors=NULL, standardize=FALSE, ...)
\item{fsize}{an integer or vector of length 3 containing the font size for the tip labels, the trait labels, and the legend text. (If a single integer is supplied, then the value will be recycled.)}
\item{colors}{a vector of colors to be passed to \code{\link{image}}. Can be a function call (e.g., \code{heat.colors(n=200)[200:1]}).}
\item{standardize}{a logical value indicating whether or not to standardize each column of \code{X} to have the same variance & mean prior to analysis.}
\item{...}{optional arguments.}
\item{...}{optional arguments. So far these include: \code{legend}, a logical value indicating whether or not to plot a figure legend (defaults to \code{legend=TRUE}); \code{labels}, a logical value indicating whether or not to plot trait labels (defaults to \code{labels=TRUE}; \code{split}, a numeric vector indicating the fraction of the horizontal dimension to use for the tree & heatmap, respectively (defaults to \code{split=c(0.5,0.5)}; \code{xlim}, \code{ylim}, and \code{mar}, defined as in \code{\link{par}}.}
}
\description{
Functions creates a multivariate phylogenetic \code{\link{heatmap}}.
Expand Down

0 comments on commit 4242df8

Please sign in to comment.