From 504fe138ad29514d5d0244b25bee72405355d89e Mon Sep 17 00:00:00 2001 From: Will Gearty Date: Wed, 30 Oct 2019 14:14:39 -0500 Subject: [PATCH 1/3] Custom expansion constant and x/y adjustments --- R/utilities.R | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/R/utilities.R b/R/utilities.R index 458d7838..97a776a8 100644 --- a/R/utilities.R +++ b/R/utilities.R @@ -856,7 +856,7 @@ markChanges<-function(tree,colors=NULL,cex=1,lwd=2,plot=TRUE){ ## function to label clades ## written by Liam J. Revell 2014, 2015 cladelabels<-function(tree=NULL,text,node,offset=NULL,wing.length=NULL,cex=1, - orientation="vertical"){ + orientation="vertical",move=c(0,0),exp=0.7){ lastPP<-get("last_plot.phylo",envir=.PlotPhyloEnv) if(is.null(tree)){ wing.length<-1 @@ -871,17 +871,17 @@ cladelabels<-function(tree=NULL,text,node,offset=NULL,wing.length=NULL,cex=1, if(is.null(offset)) offset<-0.5 xx<-mapply(labelSubTree,node,text, MoreArgs=list(tree=tree,pp=lastPP,offset=offset,wl=wing.length,cex=cex, - orientation=orientation)) + orientation=orientation,move=move,exp=exp)) } ## internal function used by cladelabels ## written by Liam J. Revell 2014, 2015 -labelSubTree<-function(tree,nn,label,pp,offset,wl,cex,orientation){ +labelSubTree<-function(tree,nn,label,pp,offset,wl,cex,orientation,move,exp){ if(is.null(wl)) wl<-1 tree<-reorder(tree) tips<-getDescendants(tree,nn) tips<-tips[tips<=Ntip(tree)] - ec<-0.7 ## expansion constant + ec<-exp ## expansion constant sw<-pp$cex*max(strwidth(tree$tip.label[tips])) sh<-pp$cex*max(strheight(tree$tip.label)) cw<-mean(strwidth(LETTERS)*cex) @@ -894,7 +894,7 @@ labelSubTree<-function(tree,nn,label,pp,offset,wl,cex,orientation){ c(y[1]-ec*sh,y[1]-ec*sh)) lines(c(h-wl*cw,h), c(y[2]+ec*sh,y[2]+ec*sh)) - text(h+cw,mean(y), + text(h+cw+move[1],mean(y)+move[2], label,srt=if(orientation=="horizontal") 0 else 90, adj=if(orientation=="horizontal") 0 else 0.5,cex=cex) } From c10a8b183b90f9393d9136ede901b770642aee9c Mon Sep 17 00:00:00 2001 From: Will Gearty Date: Wed, 30 Oct 2019 14:18:32 -0500 Subject: [PATCH 2/3] Avoid existing function name --- R/utilities.R | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/R/utilities.R b/R/utilities.R index 97a776a8..cabaa494 100644 --- a/R/utilities.R +++ b/R/utilities.R @@ -856,7 +856,7 @@ markChanges<-function(tree,colors=NULL,cex=1,lwd=2,plot=TRUE){ ## function to label clades ## written by Liam J. Revell 2014, 2015 cladelabels<-function(tree=NULL,text,node,offset=NULL,wing.length=NULL,cex=1, - orientation="vertical",move=c(0,0),exp=0.7){ + orientation="vertical",move=c(0,0),exp.c=0.7){ lastPP<-get("last_plot.phylo",envir=.PlotPhyloEnv) if(is.null(tree)){ wing.length<-1 @@ -871,17 +871,17 @@ cladelabels<-function(tree=NULL,text,node,offset=NULL,wing.length=NULL,cex=1, if(is.null(offset)) offset<-0.5 xx<-mapply(labelSubTree,node,text, MoreArgs=list(tree=tree,pp=lastPP,offset=offset,wl=wing.length,cex=cex, - orientation=orientation,move=move,exp=exp)) + orientation=orientation,move=move,exp.c=exp.c)) } ## internal function used by cladelabels ## written by Liam J. Revell 2014, 2015 -labelSubTree<-function(tree,nn,label,pp,offset,wl,cex,orientation,move,exp){ +labelSubTree<-function(tree,nn,label,pp,offset,wl,cex,orientation,move,exp.c){ if(is.null(wl)) wl<-1 tree<-reorder(tree) tips<-getDescendants(tree,nn) tips<-tips[tips<=Ntip(tree)] - ec<-exp ## expansion constant + ec<-exp.c ## expansion constant sw<-pp$cex*max(strwidth(tree$tip.label[tips])) sh<-pp$cex*max(strheight(tree$tip.label)) cw<-mean(strwidth(LETTERS)*cex) From 6fdce1a91f0712ede200156dfb1616822ffed777 Mon Sep 17 00:00:00 2001 From: Will Gearty Date: Wed, 30 Oct 2019 14:27:52 -0500 Subject: [PATCH 3/3] Add documentation --- man/cladelabels.Rd | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/man/cladelabels.Rd b/man/cladelabels.Rd index eafa4c26..6ee26d7f 100644 --- a/man/cladelabels.Rd +++ b/man/cladelabels.Rd @@ -4,7 +4,7 @@ \title{Add labels to subtrees of a plotted phylogeny} \usage{ cladelabels(tree=NULL, text, node, offset=NULL, wing.length=NULL, cex=1, - orientation="vertical") + orientation="vertical",move=c(0,0),exp.c=0.7) arc.cladelabels(tree=NULL, text, node=NULL, ln.offset=1.02, lab.offset=1.06, cex=1, orientation="curved",...) } @@ -16,6 +16,8 @@ arc.cladelabels(tree=NULL, text, node=NULL, ln.offset=1.02, \item{wing.length}{length of the wings to add to the top & bottom of the label bar (in character widths).} \item{cex}{character expansion factor.} \item{orientation}{orientation of the text. Can be \code{orientation = "vertical"} (the default) or \code{"horizontal"}.} + \item{move}{horizontal and vertical adjustments} + \item{exp.c}{expansion constant} \item{ln.offset}{line offset (as a function of total tree height) for \code{arc.cladelabels}.} \item{lab.offset}{label offset for \code{arc.cladelabels}.} \item{...}{optional arguments for \code{arc.cladelabels}.}