The R Project SVN R

Rev

Rev 68948 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 68948 Rev 69134
Line 1... Line 1...
1
% File src/library/grid/man/as.raster.Rd
1
% File src/library/grid/man/as.raster.Rd
2
% Part of the R package, https://www.R-project.org
2
% Part of the R package, https://www.R-project.org
3
% Copyright 2009-2014 R Core Team
3
% Copyright 2009-2015 R Core Team
4
% Distributed under GPL 2 or later
4
% Distributed under GPL 2 or later
5
 
5
 
6
\name{as.raster}
6
\name{as.raster}
7
\alias{is.raster}
7
\alias{is.raster}
8
\alias{as.raster}
8
\alias{as.raster}
9
\alias{as.raster.logical}
9
\alias{as.raster.logical}
10
\alias{as.raster.numeric}
10
\alias{as.raster.numeric}
-
 
11
\alias{as.raster.raw}
11
\alias{as.raster.character}
12
\alias{as.raster.character}
12
\alias{as.raster.matrix}
13
\alias{as.raster.matrix}
13
\alias{as.raster.array}
14
\alias{as.raster.array}
14
 
15
 
15
\title{Create a Raster Object}
16
\title{Create a Raster Object}
Line 19... Line 20...
19
}
20
}
20
\usage{
21
\usage{
21
is.raster(x)
22
is.raster(x)
22
as.raster(x, \dots)
23
as.raster(x, \dots)
23
 
24
 
-
 
25
\method{as.raster}{matrix}(x, max = 1, \dots)
-
 
26
\method{as.raster}{array}(x, max = 1, \dots)
-
 
27
 
24
\method{as.raster}{logical}(x, max = 1, \dots)
28
\method{as.raster}{logical}(x, max = 1, \dots)
25
\method{as.raster}{numeric}(x, max = 1, \dots)
29
\method{as.raster}{numeric}(x, max = 1, \dots)
26
\method{as.raster}{character}(x, max = 1, \dots)
30
\method{as.raster}{character}(x, max = 1, \dots)
27
\method{as.raster}{matrix}(x, max = 1, \dots)
-
 
28
\method{as.raster}{array}(x, max = 1, \dots)
31
\method{as.raster}{raw}(x, max = 255L, \dots)
29
}
32
}
30
\arguments{
33
\arguments{
31
  \item{x}{
-
 
32
    Any R object.
34
  \item{x}{any \R object.}
33
  }
-
 
34
  \item{max}{number giving the maximum of the color values range.}
35
  \item{max}{number giving the maximum of the color values range.}
35
  \item{\dots}{further arguments passed to or from other methods.}
36
  \item{\dots}{further arguments passed to or from other methods.}
36
}
37
}
37
\details{
38
\details{
38
  An object of class \code{"raster"} is a matrix of colour values as
39
  An object of class \code{"raster"} is a matrix of colour values as
Line 41... Line 42...
41
  It is not expected that the user will need to call these functions
42
  It is not expected that the user will need to call these functions
42
  directly; functions to render bitmap images in graphics packages will
43
  directly; functions to render bitmap images in graphics packages will
43
  make use of the \code{as.raster()} function to generate a raster
44
  make use of the \code{as.raster()} function to generate a raster
44
  object from their input.
45
  object from their input.
45
 
46
 
46
  The \code{as.raster()} function is generic so methods can be
47
  The \code{as.raster()} function is (S3) generic so methods can be
47
  written to convert other R objects to a raster object.
48
  written to convert other \R objects to a raster object.
48
 
49
 
49
  The default implementation for numeric matrices interprets scalar
50
  The default implementation for numeric matrices interprets scalar
50
  values on black-to-white scale.
51
  values on black-to-white scale.
51
 
52
 
52
  Raster objects can be subsetted like a matrix and it is
53
  Raster objects can be subsetted like a matrix and it is
53
  possible to assign to a subset of a raster object.
54
  possible to assign to a subset of a raster object.
54
 
55
 
55
  There is a method for converting a raster object to a matrix
56
  There is a method for converting a raster object to a
56
  (of colour strings).
57
  \code{\link{matrix}} (of colour strings).
57
 
58
 
58
  Raster objects can be compared
59
  Raster objects can be compared for equality or inequality (with each
59
  for equality or inequality (with each other or with a
-
 
60
  colour string).
60
  other or with a colour string).
61
 
61
 
62
  There is a \code{\link{is.na}} method which returns a logical matrix
62
  There is a \code{\link{is.na}} method which returns a logical matrix
63
  of the same dimensions as the raster object.  Note that \code{NA}
63
  of the same dimensions as the raster object.  Note that \code{NA}
64
  values are interpreted as the fully transparent colour by some (but
64
  values are interpreted as the fully transparent colour by some (but
65
  not all) graphics devices.
65
  not all) graphics devices.
Line 84... Line 84...
84
# Vectors are 1-column matrices ...
84
# Vectors are 1-column matrices ...
85
#   character vectors are color names ...
85
#   character vectors are color names ...
86
as.raster(hcl(0, 80, seq(50, 80, 10)))
86
as.raster(hcl(0, 80, seq(50, 80, 10)))
87
#   numeric vectors are greyscale ...
87
#   numeric vectors are greyscale ...
88
as.raster(1:5, max = 5)
88
as.raster(1:5, max = 5)
89
#   locigal vectors are black and white ...
89
#   logical vectors are black and white ...
90
as.raster(1:10 \%\% 2 == 0)
90
as.raster(1:10 \%\% 2 == 0)
91
 
91
 
92
# ... unless nrow/ncol are supplied ...
92
# ... unless nrow/ncol are supplied ...
93
as.raster(1:10 \%\% 2 == 0, nrow = 1)
93
as.raster(1:10 \%\% 2 == 0, nrow = 1)
94
 
94
 
95
# Matrix can also be logical or numeric ...
95
# Matrix can also be logical or numeric (or raw) ...
96
as.raster(matrix(c(TRUE, FALSE), nrow = 3, ncol = 2))
96
as.raster(matrix(c(TRUE, FALSE), nrow = 3, ncol = 2))
97
as.raster(matrix(1:3/4, nrow = 3, ncol = 4))
97
as.raster(matrix(1:3/4, nrow = 3, ncol = 4))
98
 
98
 
99
# An array can be 3-plane numeric (R, G, B planes) ...
99
# An array can be 3-plane numeric (R, G, B planes) ...
100
as.raster(array(c(0:1, rep(0.5, 4)), c(2, 1, 3)))
100
as.raster(array(c(0:1, rep(0.5, 4)), c(2, 1, 3)))