EVOLUTION-MANAGER
Edit File: as.raster.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>R: Create a Raster Object</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" type="text/css" href="R.css" /> </head><body> <table width="100%" summary="page for as.raster {grDevices}"><tr><td>as.raster {grDevices}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>Create a Raster Object</h2> <h3>Description</h3> <p>Functions to create a raster object (representing a bitmap image) and coerce other objects to a raster object. </p> <h3>Usage</h3> <pre> is.raster(x) as.raster(x, ...) ## S3 method for class 'matrix' as.raster(x, max = 1, ...) ## S3 method for class 'array' as.raster(x, max = 1, ...) ## S3 method for class 'logical' as.raster(x, max = 1, ...) ## S3 method for class 'numeric' as.raster(x, max = 1, ...) ## S3 method for class 'character' as.raster(x, max = 1, ...) ## S3 method for class 'raw' as.raster(x, max = 255L, ...) </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>x</code></td> <td> <p>any <span style="font-family: Courier New, Courier; color: #666666;"><b>R</b></span> object.</p> </td></tr> <tr valign="top"><td><code>max</code></td> <td> <p>number giving the maximum of the color values range.</p> </td></tr> <tr valign="top"><td><code>...</code></td> <td> <p>further arguments passed to or from other methods.</p> </td></tr> </table> <h3>Details</h3> <p>An object of class <code>"raster"</code> is a matrix of colour values as given by <code><a href="rgb.html">rgb</a></code> representing a bitmap image. </p> <p>It is not expected that the user will need to call these functions directly; functions to render bitmap images in graphics packages will make use of the <code>as.raster()</code> function to generate a raster object from their input. </p> <p>The <code>as.raster()</code> function is (S3) generic so methods can be written to convert other <span style="font-family: Courier New, Courier; color: #666666;"><b>R</b></span> objects to a raster object. </p> <p>The default implementation for numeric matrices interprets scalar values on black-to-white scale. </p> <p>Raster objects can be subsetted like a matrix and it is possible to assign to a subset of a raster object. </p> <p>There is a method for converting a raster object to a <code><a href="../../base/html/matrix.html">matrix</a></code> (of colour strings). </p> <p>Raster objects can be compared for equality or inequality (with each other or with a colour string). </p> <p>There is a <code><a href="../../base/html/NA.html">is.na</a></code> method which returns a logical matrix of the same dimensions as the raster object. Note that <code>NA</code> values are interpreted as the fully transparent colour by some (but not all) graphics devices. </p> <h3>Value</h3> <p>For <code>as.raster()</code>, a raster object. </p> <p>For <code>is.raster()</code>, a logical indicating whether <code>x</code> is a raster object. </p> <h3>Note</h3> <p>Raster images are internally represented row-first, which can cause confusion when trying to manipulate a raster object. The recommended approach is to coerce a raster to a matrix, perform the manipulation, then convert back to a raster. </p> <h3>Examples</h3> <pre> # A red gradient as.raster(matrix(hcl(0, 80, seq(50, 80, 10)), nrow = 4, ncol = 5)) # Vectors are 1-column matrices ... # character vectors are color names ... as.raster(hcl(0, 80, seq(50, 80, 10))) # numeric vectors are greyscale ... as.raster(1:5, max = 5) # logical vectors are black and white ... as.raster(1:10 %% 2 == 0) # ... unless nrow/ncol are supplied ... as.raster(1:10 %% 2 == 0, nrow = 1) # Matrix can also be logical or numeric (or raw) ... as.raster(matrix(c(TRUE, FALSE), nrow = 3, ncol = 2)) as.raster(matrix(1:3/4, nrow = 3, ncol = 4)) # An array can be 3-plane numeric (R, G, B planes) ... as.raster(array(c(0:1, rep(0.5, 4)), c(2, 1, 3))) # ... or 4-plane numeric (R, G, B, A planes) as.raster(array(c(0:1, rep(0.5, 6)), c(2, 1, 4))) # subsetting r <- as.raster(matrix(colors()[1:100], ncol = 10)) r[, 2] r[2:4, 2:5] # assigning to subset r[2:4, 2:5] <- "white" # comparison r == "white" </pre> <hr /><div style="text-align: center;">[Package <em>grDevices</em> version 3.6.0 <a href="00Index.html">Index</a>]</div> </body></html>