[Dplr-commits] r912 - in pkg/dplR: . R man

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Mon Nov 10 20:45:28 CET 2014


Author: mvkorpel
Date: 2014-11-10 20:45:28 +0100 (Mon, 10 Nov 2014)
New Revision: 912

Added:
   pkg/dplR/man/rasterPlot.Rd
Modified:
   pkg/dplR/ChangeLog
   pkg/dplR/DESCRIPTION
   pkg/dplR/NAMESPACE
   pkg/dplR/R/rasterPlot.R
Log:
Exported and documented rasterPlot()


Modified: pkg/dplR/ChangeLog
===================================================================
--- pkg/dplR/ChangeLog	2014-11-10 19:40:39 UTC (rev 911)
+++ pkg/dplR/ChangeLog	2014-11-10 19:45:28 UTC (rev 912)
@@ -3,7 +3,7 @@
 File: NAMESPACE
 ---------------
 
-- Added latexify() and latexDate() to export list
+- Added rasterPlot, latexify() and latexDate() to export list
 - Import readPNG from png.
 - Import more functions from grid.
 
@@ -95,9 +95,8 @@
 New file rasterPlot.R
 ---------------------
 
-- New function rasterPlot(), internal to the package.  Adds a
-  raster image drawn with low level graphics commands to the current
-  high level plot.
+- New function rasterPlot().  Adds a raster image drawn with low
+  level graphics commands to the current high level plot.
 
 Files: rcompact.c, readloop.c
 -----------------------------

Modified: pkg/dplR/DESCRIPTION
===================================================================
--- pkg/dplR/DESCRIPTION	2014-11-10 19:40:39 UTC (rev 911)
+++ pkg/dplR/DESCRIPTION	2014-11-10 19:45:28 UTC (rev 912)
@@ -3,7 +3,7 @@
 Type: Package
 Title: Dendrochronology Program Library in R
 Version: 1.6.1
-Date: 2014-11-06
+Date: 2014-11-10
 Authors at R: c(person("Andy", "Bunn", role = c("aut", "cph",
         "cre", "trl"), email = "andy.bunn at wwu.edu"), person("Mikko",
         "Korpela", role = c("aut", "trl")), person("Franco", "Biondi",

Modified: pkg/dplR/NAMESPACE
===================================================================
--- pkg/dplR/NAMESPACE	2014-11-10 19:40:39 UTC (rev 911)
+++ pkg/dplR/NAMESPACE	2014-11-10 19:45:28 UTC (rev 912)
@@ -42,7 +42,7 @@
        write.compact, write.crn, write.rwl, write.tridas,
        write.tucson, plot.rwl, interseries.cor, summary.rwl,
        plot.crn, insert.ring, delete.ring, xskel.ccf.plot, xskel.plot,
-       latexify, latexDate)
+       latexify, latexDate, rasterPlot)
 
 S3method(print, redfit)
 S3method(plot, rwl)

Modified: pkg/dplR/R/rasterPlot.R
===================================================================
--- pkg/dplR/R/rasterPlot.R	2014-11-10 19:40:39 UTC (rev 911)
+++ pkg/dplR/R/rasterPlot.R	2014-11-10 19:45:28 UTC (rev 912)
@@ -1,29 +1,5 @@
-### Add raster elements to the active high-level plot.  The given
-### plotting commands are drawn using a temporary png() device.  The
-### raster image is read into memory and added to the original plot.
-###
-### Written by Mikko Korpela
-###
-### Arguments:
-### x          Low-level plotting commands representing elements to be added
-###            to the current plot.  Examples: lines(), points(), text(),
-###            mtext(), .filled.contour()
-### res        Resolution in points per inch.
-###            Estimated useful range: 100 - 300.
-### region     Draw in the plot region or the figure region?
-###            The figure region contains the plot region and margins.
-###            Plotting in the outer margin is not supported.
-### antialias  Antialiasing option for png().  See argument 'antialias'
-###            in ?png.  "none" is preferred for images in which color
-###            signifies value of data.  The default (missing argument)
-###            is probably good for line plots.
-### interpolate
-###            Argument passed to rasterImage().  A logical flag.
-###            The default is TRUE: use linear interpolation.
-###            Analogously to 'antialias', FALSE is preferred when
-###            color maps to value.
-rasterPlot <- function(x, res = 150, region=c("plot", "figure"), antialias,
-                       interpolate = TRUE) {
+rasterPlot <- function(expr, res = 150, region=c("plot", "figure"), antialias,
+                       bg = "transparent", interpolate = TRUE, ...) {
     if (identical(dev.capabilities("rasterImage")[["rasterImage"]], "no")) {
         stop("device does not support raster images")
     }
@@ -50,10 +26,10 @@
     fname <- tempfile(fileext = ".png")
     if (missing(antialias)) {
         png(fname, width = pngWidthHeight[1], height = pngWidthHeight[2],
-            units = "in", res = res, bg = "transparent")
+            units = "in", res = res, bg = bg, ...)
     } else {
         png(fname, width = pngWidthHeight[1], height = pngWidthHeight[2],
-            units = "in", res = res, bg = "transparent", antialias = antialias)
+            units = "in", res = res, bg = bg, antialias = antialias, ...)
     }
     ## Record things to do on exit (will be removed from list one-by-one)
     on.exit(dev.off())
@@ -70,10 +46,10 @@
     ## Copy graphical parameters from original device to png:
     ## (margins), coordinates of plot region, etc.
     par(op)
-    ## Evaluate the plotting commands 'x' in the environment of the
+    ## Evaluate the plotting commands 'expr' in the environment of the
     ## caller of rasterPlot()
     pf <- parent.frame()
-    eval(x, pf)
+    eval(expr, pf)
     on.exit(dev.set(curDev))
     on.exit(unlink(fname), add=TRUE)
     ## Close the png device
@@ -119,4 +95,5 @@
                     xright = figRight, ytop = figTop,
                     interpolate = interpolate)
     }
+    invisible(NULL)
 }

Added: pkg/dplR/man/rasterPlot.Rd
===================================================================
--- pkg/dplR/man/rasterPlot.Rd	                        (rev 0)
+++ pkg/dplR/man/rasterPlot.Rd	2014-11-10 19:45:28 UTC (rev 912)
@@ -0,0 +1,94 @@
+\name{rasterPlot}
+\alias{rasterPlot}
+\title{
+  Add Raster Elements to Plot
+}
+\description{
+  This function takes plotting commands and uses a temporary
+  \code{\link{png}} bitmap graphics device to capture their output.  The
+  resulting raster image is drawn in the plot or figure region of the
+  active high-level plot.
+}
+\usage{
+rasterPlot(expr, res = 150, region = c("plot", "figure"), antialias,
+           bg = "transparent", interpolate = TRUE, \dots)
+}
+\arguments{
+  \item{expr}{
+    Low-level plotting commands (\code{lines}, \code{points},
+    \code{text}, \ldots) representing elements to be added to the
+    current plot.  A \code{\link{call}} or an \code{\link{expression}}.
+  }
+  \item{res}{
+    Resolution in points per inch (ppi).  A numeric value.  Suggested
+    values for different types of display media are given in
+    \code{\link{compactPDF}}.  For example, the default 150 ppi
+    corresponds to \dQuote{ebook} quality.
+  }
+  \item{region}{
+    The function can draw in the \code{"plot"} region or the
+    \code{"figure"} region which also includes \code{"mar"} margins (see
+    \code{\link{par}}).  If the drawing commands in \code{\var{expr}}
+    contain no material for the margins, the default \code{"plot"} is
+    optimal.  Plotting in the outer margins (\code{"oma"} in
+    \code{\link{par}}) is not supported.
+  }
+  \item{antialias}{
+    Antialiasing argument passed to \code{\link{png}}.  The default
+    (missing argument) is probably good for line plots but
+    \code{"none"} is preferred for images in which color signifies value
+    of data.
+  }
+  \item{bg}{
+    Background color of the raster plot, an argument passed to
+    \code{\link{png}}.  If the default \code{"transparent"} does not
+    work, try \code{"white"} or another color.  Note that a
+    non-transparent background will mask any previous content in the
+    figure or plot region, depending on the value of \code{\var{region}}.
+  }
+  \item{interpolate}{
+    Argument passed to \code{\link{rasterImage}}.  A \code{logical}
+    flag.  The default is \code{TRUE}: use linear interpolation.
+    Analogously to \code{\var{antialias}}, \code{FALSE} is preferred
+    when color maps to value.
+  }
+  \item{\dots}{
+    Other arguments to \code{\link{png}}.
+  }
+}
+\details{
+  The appropriate graphical parameters of the current graphics device
+  are copied to the temporary \code{\link{png}} device.  Therefore the
+  appearance of the raster contents should be almost the same as when
+  directly drawn.
+
+  The call or expression \code{\var{expr}} is evaluated in the
+  environment of the caller.
+
+  Resizing a graphics device after a call to this function may distort
+  the image.  For example, circle symbols will become ellipses if the
+  width to height ratio is not maintained (see \sQuote{Examples}).  This
+  is in contrast to a standard plot in a display graphics device,
+  e.g. \code{\link{x11}}, where text and symbols maintain their size
+  when the device is resized.
+}
+\value{
+  No return value.  Used for the side effects.
+}
+\author{
+  Mikko Korpela
+}
+\note{
+  The graphics device used for the output must have support for
+  including raster images.  See \code{"rasterImage"} in
+  \code{\link{dev.capabilities}}.
+
+  The \R build must have a functional \code{\link{png}} device, which
+  requires one of the following \code{\link{capabilities}}:
+  \code{"png"}, \code{"aqua"} or \code{"cairo"}.
+}
+\examples{plot(1:5, type = "n")
+foo <- runif(5, min = 1, max = 5)
+rasterPlot(quote(points(foo)))
+}
+\keyword{ aplot }


Property changes on: pkg/dplR/man/rasterPlot.Rd
___________________________________________________________________
Added: svn:eol-style
   + native



More information about the Dplr-commits mailing list