[Vegan-commits] r1062 - in pkg/vegan: R inst

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Wed Oct 28 18:47:38 CET 2009


Author: jarioksa
Date: 2009-10-28 18:47:38 +0100 (Wed, 28 Oct 2009)
New Revision: 1062

Modified:
   pkg/vegan/R/msoplot.R
   pkg/vegan/inst/ChangeLog
Log:
msoplot uses standard legend()

Modified: pkg/vegan/R/msoplot.R
===================================================================
--- pkg/vegan/R/msoplot.R	2009-10-28 13:39:56 UTC (rev 1061)
+++ pkg/vegan/R/msoplot.R	2009-10-28 17:47:38 UTC (rev 1062)
@@ -6,6 +6,7 @@
         object <- object.cca
         vario <- object$vario
         grain <- object$grain
+        hasSig <- is.numeric(object$vario$CA.signif)
         z <- qnorm(alpha/2)
         if (is.numeric(vario$CA.signif)) {
             vario <- vario[, -ncol(vario)]
@@ -14,6 +15,8 @@
         b <- ncol(vario) - 3
         label <- c("", "", "", "Total variance", "Explained plus residual", 
                    "Residual variance", "Explained variance", "Conditioned variance")
+        ci.lab <- "C.I. for total variance"
+        sign.lab <- if(hasSig) "Sign. autocorrelation" else NULL
         ## You should not change par, or at least you must put
         ## back the old values when exiting:
         ## op <- par(omi = c(0.5, 0.5, 0, 0))
@@ -31,59 +34,40 @@
             lines(vario$Dist, vario$All - z * vario$se, lty = 1, ...)
             lines(vario$Dist, vario$Sum, type = "b", lty = 2, 
                   pch = 3, ...)
+            ## Legend
+            legend("topleft", c(label[c(2,b:3)+3], ci.lab, sign.lab),
+                   lty=c(c(1,2,1,1,1)[2:b], 1, if(hasSig) NA),
+                   pch=c(3, (6:(b+3))-6, NA, if(hasSig) 15)
+                   )
             for (i in 6:(b + 3)) {
                 lines(vario$Dist, vario[, i], type = "b", lty = 1, 
                       pch = i - 6, ...)
-                points(x = 1.2 * grain,
-                       y = ymax - ymax * (b + 6 - i)/20, pch = i - 6, ...)
             }
-            text(x = rep(2 * grain, b - 1), y = ymax - ymax * 
-                 c(2:b)/20, label = label[c(2, b:3) + 3], pos = 4, 
-                 cex = 1.2, ...)
-            points(x = 1.2 * grain, y = ymax - ymax * 2/20, pch = 3, ...)
-            for (i in 2:b) {
-                lines(x = c(0.7, 1.1) * grain,
-                      y = rep(ymax -  ymax * i/20, 2),
-                      lty = c(1, 2, 1, 1, 1)[i])
-                lines(x = c(1.3, 1.7) * grain,
-                      y = rep(ymax -  ymax * i/20, 2), lty = c(1, 2, 1, 1, 1)[i])
-            }
             text(x = c(vario$Dist), y = rep(0, length(vario$Dist)), 
                  label = c(vario$n), cex = 0.8, ...)
             lines(x = rep(max(object$H)/2, 2), y = c(-10, ymax + 
                                                10), lty = 3, ...)
-            text(x = 2 * grain, y = ymax - ymax/20, label = "C.I. for total variance", 
-                 pos = 4, cex = 1.2, ...)
-            lines(x = c(0.7, 1.7) * grain, y = rep(ymax - ymax/20, 2),
-                  lty = 1, ...)
         }
         else {
             plot(vario$Dist, vario$All, type = "b", lty = 1, 
                  pch = 0, xlab = "Distance", ylab = "Variance", 
                  ylim = c(0, ymax), cex.lab = 1.2, ...)
             lines(c(0, 10), rep(object$tot.chi, 2), lty = 5, ...)
-            lines(x = c(0.7, 1.7) * grain, y = rep(ymax - ymax * 
-                                           b/20, 2), lty = 5, ...)
-            text(x = 2 * grain, y = ymax - ymax * b/20, label = "Global variance estimate", 
-                 pos = 4, cex = 1.2, ...)
             text(x = c(vario$Dist), y = rep(0, length(vario$Dist)), 
                  label = c(vario$n), cex = 0.8)
             lines(x = rep(max(object$H)/2, 2), y = c(-10, ymax + 
                                                10), lty = 3, ...)
-            text(x = 2 * grain, y = ymax - ymax/20, label = "Total variance", 
-                 pos = 4, cex = 1.2, ...)
-            lines(x = c(0.7, 1.7) * grain, y = rep(ymax - ymax/20, 
-                                           2), lty = 1, ...)
+            legend("topleft",
+                   c("Total variance","Global variance estimate",
+                     if(hasSig) "Sign. autocorrelation"),
+                   lty=c(1,5, if(hasSig) NA),
+                   pch = if(hasSig) c(NA,NA,15) else NULL)
         }
     }
-    if (is.numeric(object$vario$CA.signif)) {
+    if (hasSig) {
         a <- c(1:nrow(object$vario))[object$vario$CA.signif < 
                                      alpha]
         points(vario$Dist[a], object$vario$CA[a], pch = 15, ...)
-        points(x = 1.2 * grain, y = ymax - ymax * (b + 1)/20, 
-               pch = 15, ...)
-        text(x = 2 * grain, y = ymax - ymax * (b + 1)/20, pos = 4, 
-             cex = 1.2, label = c("Sign. autocorrelation"), ...)
         if (is.numeric(object$CCA$rank)) {
             inflation <- 1 - weighted.mean(object$vario$CA, object$vario$n)/
                 weighted.mean(object$vario$CA[-a], 

Modified: pkg/vegan/inst/ChangeLog
===================================================================
--- pkg/vegan/inst/ChangeLog	2009-10-28 13:39:56 UTC (rev 1061)
+++ pkg/vegan/inst/ChangeLog	2009-10-28 17:47:38 UTC (rev 1062)
@@ -4,6 +4,9 @@
 
 Version 1.16-32 (opened October 24, 2009)
 
+	* msoplot: uses standard legend() to display info instead of hand
+	crafted positioning of the legend information.
+
 	* ordisurf: plotting main title was broken with NA handling in
 	1.16-31 (r1049). Also increased grid density and adjusted pushing
 	out limits of convex hull.



More information about the Vegan-commits mailing list