[Desire-commits] r24 - in packages/desire: R man

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sat May 31 00:20:11 CEST 2008


Author: olafm
Date: 2008-05-31 00:20:11 +0200 (Sat, 31 May 2008)
New Revision: 24

Modified:
   packages/desire/R/dsplot.R
   packages/desire/man/dsplot.Rd
Log:
* Mirror dsplot
* Add origin indicator


Modified: packages/desire/R/dsplot.R
===================================================================
--- packages/desire/R/dsplot.R	2008-05-30 07:27:56 UTC (rev 23)
+++ packages/desire/R/dsplot.R	2008-05-30 22:20:11 UTC (rev 24)
@@ -9,7 +9,7 @@
 
 dsplot <- function(expr, f,
                    from=NULL, to=NULL, n=101,
-                   interest=NULL,
+                   show.zero=TRUE, interest=NULL,
                    main="Desirability Plot", sub=NULL,...) {
   sexpr <- substitute(expr)
   if (is.name(sexpr)) {
@@ -23,7 +23,7 @@
 
   ## Evaluate expression:
   x <- seq(from, to, length.out=n)
-  y <- eval(expr, envir = list(x = x), enclos = parent.frame())
+  y <- eval(expr, envir=list(x=x), enclos=parent.frame())
 
   if (length(interest) > 0) {
     xi <- interest
@@ -42,38 +42,41 @@
   par(oma=oma)
 
   ## Layout of plots: 1/3 desirability, 2/3 expression
-  layout(matrix(c(2, 1), ncol=2),
-         widths=c(1/3, 2/3),
+  layout(matrix(c(1, 2), ncol=2),
+         widths=c(2/3, 1/3),
          heights=c(1,1))
 
   ## Expression plot
-  par(mar=c(5, 3, 1, 1))
-  plot(x, y, type="l", ...)
-
+  par(mar=c(5, 2, 1, 3))
+  plot(x, y, type="l", yaxt="n", ...)
+  axis(4)
+  ## Global y axis label
+  mtext(sexpr, side=2, line=1)
+  
+  if (show.zero)
+    abline(h=0, col="grey", lty=2)
   if (length(interest) > 0) {
-    xmin <- par("usr")[1]
+    xmax <- par("usr")[2]
     ymin <- par("usr")[3]
     segments(xi, ymin, xi, yi, col="red", lty=2)
-    segments(xmin, yi, xi, yi, col="red", lty=2)
+    segments(xmax, yi, xi, yi, col="red", lty=2)
   }
   ## Desirability plot
-  par(mar=c(5, 2, 1, 0))
-  y <- seq(min(y), max(y), length.out=n)
-  plot(1-f(y), y,
+  par(mar=c(5, 0, 1, 2))
+  y <- y[is.finite(y)] ## Remove +/- Inf values (poles)
+  y <- seq(min(y), max(y), length.out=n)  
+  plot(f(y), y,
        xlab=substitute(d(sexpr)), ylab=sexpr,
-       type="l", xaxt="n", yaxt="n", ...)
-  axis(4, labels=FALSE)
-  tck <- axTicks(1)  
-  axis(1, at=tck, labels=1-tck)
+       type="l", yaxt="n", ...)
+  axis(2, labels=FALSE)
 
+  if (show.zero)
+    abline(h=0, col="grey", lty=2)
   if (length(interest) > 0) {
-    xmax <- par("usr")[2]
-    segments(xmax, yi, 1-di, yi, col="red", lty=2)
+    xmin <- par("usr")[1]
+    segments(xmin, yi, di, yi, col="red", lty=2)
   }
   
-  ## Global y axis label
-  mtext(sexpr, side=2, line=1)
-
   ## Add main/sub title to plot:
   if (!is.null(main))
     mtext(main, side=3, outer=TRUE)

Modified: packages/desire/man/dsplot.Rd
===================================================================
--- packages/desire/man/dsplot.Rd	2008-05-30 07:27:56 UTC (rev 23)
+++ packages/desire/man/dsplot.Rd	2008-05-30 22:20:11 UTC (rev 24)
@@ -5,7 +5,7 @@
   TBD
 }
 \usage{
-dsplot(expr, f, from = NULL, to = NULL, n = 101, interest = NULL, main = "Desirability Plot", sub = NULL, ...)
+dsplot(expr, f, from = NULL, to = NULL, n = 101, show.zero = TRUE, interest = NULL, main = "Desirability Plot", sub = NULL, ...)
 }
 \arguments{
   \item{expr}{an expression written as a function of 'x', or alternatively
@@ -13,6 +13,7 @@
   \item{f}{desirability function}
   \item{from,to}{the range over which the function will be plotted.}
   \item{n}{integer; the number of x values at which to evaluate.}
+  \item{show.zero}{add dotted line to visualize the origin}
   \item{interest}{vector of interesting points}
   \item{main}{an overall title for the plot}
   \item{sub}{a subtitle for the plot}



More information about the Desire-commits mailing list