[Phylobase-commits] r267 - branches/pdcgsoc/R

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Thu Aug 7 03:38:48 CEST 2008


Author: pdc
Date: 2008-08-07 03:38:48 +0200 (Thu, 07 Aug 2008)
New Revision: 267

Modified:
   branches/pdcgsoc/R/treePlot.R
Log:
fixes for empty plot window base graphics and missing values in trait data

Modified: branches/pdcgsoc/R/treePlot.R
===================================================================
--- branches/pdcgsoc/R/treePlot.R	2008-08-07 00:59:55 UTC (rev 266)
+++ branches/pdcgsoc/R/treePlot.R	2008-08-07 01:38:48 UTC (rev 267)
@@ -33,7 +33,12 @@
     # TODO add symbols at the nodes, allow coloirng and sizing downViewport approach?
     # TODO cladogram methods incorrect
     # TODO abstract, make ultrametric? good algorithms for this?
+    # call plot.new so that gridBase plots work properly
+    # calls to base plot functions need to be cleared w/ par(new = T) which fails
+    # if no plot is present TODO perhpas there's a better solution than calling plot.new
+    plot.new()
     grid.newpage()
+    
     ## because we may reoder the tip, we need to update the phy objec
     
     if(!plot.data) {
@@ -54,13 +59,16 @@
     
     if(plot.data) {
         if(tip.plot.fun == "density") {
-
-            tmin <- min(tdata(phy, which = 'tip'))
-            tmax <- max(tdata(phy, which = 'tip'))
+            tmin <- min(tdata(phy, which = 'tip'), na.rm = T)
+            tmax <- max(tdata(phy, which = 'tip'), na.rm = T)
             tip.plot.fun <- function(x) {
-                par(plt=gridFIG())   
-                par(new=TRUE)          
-                plot(density(t(x)),xlim=c(tmin,tmax),axes=FALSE,main="",xlab="",ylab="")
+                if(!all(is.na(x))) {
+                    # hack, set th plotting region to the grid fig region
+                    par(plt = gridFIG(), new = TRUE)
+                    dens <- density(x, na.rm = TRUE)
+                    plot.density(dens, xlim = c(tmin, tmax), axes = FALSE, 
+                                main = "", xlab = "", ylab = "")
+                }
             }
            
         }



More information about the Phylobase-commits mailing list