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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Thu Aug 7 23:22:18 CEST 2008


Author: pdc
Date: 2008-08-07 23:22:18 +0200 (Thu, 07 Aug 2008)
New Revision: 271

Modified:
   branches/pdcgsoc/R/treePlot.R
Log:
bugfixes for a couple gridBase issues

Modified: branches/pdcgsoc/R/treePlot.R
===================================================================
--- branches/pdcgsoc/R/treePlot.R	2008-08-07 04:35:44 UTC (rev 270)
+++ branches/pdcgsoc/R/treePlot.R	2008-08-07 21:22:18 UTC (rev 271)
@@ -1,4 +1,4 @@
-treePlot <- function(phy, 
+`treePlot` <- function(phy, 
                      type = c('phylogram', 'cladogram', 'fan'), 
                      show.tip.label = TRUE,
                      show.node.label = FALSE, 
@@ -36,47 +36,47 @@
     # 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) {
-        phyplotlayout <- grid.layout(nrow = 1, ncol = 1)
-        # TODO for very long plots, alternative margin setting useful
-        pushViewport(viewport(width = width, height = height, 
-                            layout = phyplotlayout, 
-                            name = 'phyplotlayout', angle = -rot))
-        pushViewport(viewport(layout.pos.col = 1, layout.pos.row = 1))
-            tree.plot(xxyy, type, show.tip.label, show.node.label, 
-                edge.color, node.color, tip.color, 
-                edge.width, rot)
-        upViewport()
-        upViewport()
-        # TODO should return something useful
-        return(invisible())
-    }
-    
+    grid.newpage()
     if(plot.data) {
         if(!is.function(tip.plot.fun)) {
             if(tip.plot.fun == "density") {
                 if(!require(gridBase)) {
-                    stop('To plot using base graphics (including the "density" plot) 
-                                           you need install the "gridBase" package')
+                    stop('To plot using base graphics (including the "density"              
+                            plot) you need install the "gridBase" package')
                 }
+            }
+                plot.new()
                 tmin <- min(tdata(phy, which = 'tip'), na.rm = T)
                 tmax <- max(tdata(phy, which = 'tip'), na.rm = T)
                 tip.plot.fun <- function(x) {
+                    # par(omi = c(0,0,0,0))
+                    par(plt = gridPLT(), new = TRUE)
                     if(!all(is.na(x))) {
-                        # hack, set th plotting region to the grid fig region
-                        par(plt = gridFIG(), new = TRUE)
+                        # hack, set the plotting region to the grid fig region
                         dens <- density(x, na.rm = TRUE)
-                        plot.density(dens, xlim = c(tmin, tmax), axes = FALSE, 
-                                    main = "", xlab = "", ylab = "")
+                        plot.density(dens, xlim = c(tmin, tmax), axes = FALSE,      
+                            mar = c(0,0,0,0), main = "", xlab = "", ylab = "")
                     }
                 }
             }           
+        } else {
+            phyplotlayout <- grid.layout(nrow = 1, ncol = 1)
+            # TODO for very long plots, alternative margin setting useful
+            pushViewport(viewport(width = width, height = height, 
+                                layout = phyplotlayout, 
+                                name = 'phyplotlayout', angle = -rot))
+            pushViewport(viewport(layout.pos.col = 1, layout.pos.row = 1))
+                tree.plot(xxyy, type, show.tip.label, show.node.label, 
+                    edge.color, node.color, tip.color, 
+                    edge.width, rot)
+            upViewport()
+            upViewport()
+            # TODO should return something useful
+            return(invisible())
         }
+        
         if(is.function(tip.plot.fun)) {
             datalayout <- grid.layout(ncol = 2,
                 width = unit(c(1, 1/Ntips), c('null', 'null')) 
@@ -85,11 +85,6 @@
                 pushViewport(viewport(width = width, height = height, 
                                     layout = datalayout, 
                                     name = 'datalayout', angle = -rot))
-                pushViewport(viewport(layout.pos.col = 1))
-                    tree.plot(xxyy, type, show.tip.label, show.node.label, 
-                        edge.color, node.color, tip.color, 
-                        edge.width, rot)
-                upViewport()
                 
                 pushViewport(viewport(
                     yscale = c(-0.5/Ntips, 1 + 0.5/Ntips), 
@@ -112,8 +107,13 @@
                         tip.plot.fun(t(tdata(phy, which = 'tip')[i, ]))
                     upViewport()
                 }
+                pushViewport(viewport(layout.pos.col = 1))
+                    tree.plot(xxyy, type, show.tip.label, show.node.label, 
+                        edge.color, node.color, tip.color, 
+                        edge.width, rot)
                 upViewport()
                 upViewport()
+                upViewport()
         } else {
             # use phylobubbles as default
             dlabwdth <- max(stringWidth(colnames(phy at tip.data)))
@@ -137,7 +137,6 @@
                 upViewport()
             upViewport()
         }
-    }
 }
 
 tree.plot <- function(xxyy, type, show.tip.label, show.node.label, edge.color, 
@@ -428,4 +427,3 @@
 
     popViewport()
 }
-



More information about the Phylobase-commits mailing list