The R Project SVN R

Rev

Rev 61153 | Rev 74526 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
42333 ripley 1
% File src/library/graphics/man/matplot.Rd
2
% Part of the R package, http://www.R-project.org
59039 ripley 3
% Copyright 1995-2007 R Core Team
42333 ripley 4
% Distributed under GPL 2 or later
5
 
27442 ripley 6
\name{matplot}
56186 murdoch 7
\alias{matplot}
27442 ripley 8
\alias{matpoints}
9
\alias{matlines}
10
\title{Plot Columns of Matrices}
11
\usage{
48379 maechler 12
matplot(x, y, type = "p", lty = 1:5, lwd = 1, lend = par("lend"),
13
        pch = NULL,
38463 maechler 14
        col = 1:6, cex = NULL, bg = NA,
30915 ripley 15
        xlab = NULL, ylab = NULL, xlim = NULL, ylim = NULL,
27442 ripley 16
        \dots, add = FALSE, verbose = getOption("verbose"))
30912 ripley 17
 
18
matpoints(x, y, type = "p", lty = 1:5, lwd = 1, pch = NULL,
19
          col = 1:6, \dots)
20
 
21
matlines (x, y, type = "l", lty = 1:5, lwd = 1, pch = NULL,
22
          col = 1:6, \dots)
27442 ripley 23
}
24
\arguments{
25
  \item{x,y}{vectors or matrices of data for plotting.  The number of
26
    rows should match.  If one of them are missing, the other is taken
27
    as \code{y} and an \code{x} vector of \code{1:n} is used.
28
    Missing values (\code{NA}s) are allowed.}
29
  \item{type}{character string (length 1 vector) or vector of 1-character
30
    strings indicating the type of plot for each
31
    column of \code{y}, see \code{\link{plot}} for all possible
32
    \code{type}s.  The first character of \code{type}
33
    defines the first plot, the second character the second, etc.
34
    Characters in \code{type} are cycled through; e.g., \code{"pl"}
35
    alternately plots points and lines.}
48379 maechler 36
  \item{lty,lwd,lend}{vector of line types, widths, and end styles.
27442 ripley 37
    The first element is for the first column, the second element for
38
    the second column, etc., even if lines are not plotted for all
39
    columns. Line types will be used cyclically until all plots are
40
    drawn.}
41
  \item{pch}{character string or vector of 1-characters or integers for
42
    plotting characters, see \code{\link{points}}.
43
    The first character is the plotting-character for the first plot,
44
    the second for the second, etc.  The default is the digits (1
44331 maechler 45
    through 9, 0) then the lowercase and uppercase letters.
27442 ripley 46
%%__FIXME__ Which of the following is still true; what's the "right" UI ?
47
%  To mix special plotting symbols (those specified by integers) and
61153 ripley 48
%  plotting characters, either use character escapes \code{pch = "Xe002"}
27442 ripley 49
%  or figure out the numeric equivalent of the ASCII character,
61168 ripley 50
%  \code{pch = c(88, 2)}.
27442 ripley 51
  }
52
  \item{col}{vector of colors.  Colors are used cyclically.}
35243 ripley 53
  \item{cex}{vector of character expansion sizes, used cyclically.
54
    This works as a multiple of \code{\link{par}("cex")}.  \code{NULL} is
55
    equivalent to \code{1.0}. }
42961 ripley 56
  \item{bg}{vector of background (fill) colors for the open plot
61153 ripley 57
    symbols given by \code{pch = 21:25} as in \code{\link{points}}.  The
38463 maechler 58
    default \code{NA} corresponds to the one of the underlying function
59
    \code{\link{plot.xy}}.}
27442 ripley 60
  \item{xlab, ylab}{titles for x and y axes, as in \code{\link{plot}}.}
61
  \item{xlim, ylim}{ranges of x and y axes, as in \code{\link{plot}}.}
62
  \item{\dots}{Graphical parameters (see \code{\link{par}}) and any further
63
    arguments of \code{plot}, typically \code{\link{plot.default}}, may also be
64
    supplied as arguments to this function.  Hence, the high-level
65
    graphics control arguments described under \code{\link{par}} and the
66
    arguments to \code{\link{title}} may be supplied to this function.}
67
  \item{add}{logical.  If \code{TRUE}, plots are added to current one,
68
    using \code{\link{points}} and \code{\link{lines}}.}
69
  \item{verbose}{logical.  If \code{TRUE}, write one line of what is
70
    done.}
71
}
72
\section{Side Effects}{Function \code{matplot} generates a new plot;
73
  \code{matpoints} and \code{matlines} add to the current one.}
74
\description{
75
  Plot the columns of one matrix against the columns of another.
76
}
77
\details{
78
  Points involving missing values are not plotted.
79
 
80
  The first column of \code{x} is plotted against the first column of
81
  \code{y}, the second column of \code{x} against the second column of
82
  \code{y}, etc.  If one matrix has fewer columns, plotting will cycle
83
  back through the columns again.  (In particular, either \code{x} or
84
  \code{y} may be a vector, against which all columns of the other
85
  argument will be plotted.)
86
 
87
  The first element of \code{col, cex, lty, lwd} is used to plot the axes
88
  as well as the first line.
89
 
90
  Because plotting symbols are drawn with lines and because these
91
  functions may be changing the line style, you should probably specify
61153 ripley 92
  \code{lty = 1} when using plotting symbols.
27442 ripley 93
}
94
\references{
95
  Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988)
96
  \emph{The New S Language}.
47262 ripley 97
  Wadsworth & Brooks/Cole.
27442 ripley 98
}
99
\seealso{
100
  \code{\link{plot}}, \code{\link{points}}, \code{\link{lines}},
101
  \code{\link{matrix}}, \code{\link{par}}.
102
}
103
\examples{
41502 ripley 104
require(grDevices)
27442 ripley 105
matplot((-4:5)^2, main = "Quadratic") # almost identical to plot(*)
106
sines <- outer(1:20, 1:4, function(x, y) sin(x / 20 * pi * y))
107
matplot(sines, pch = 1:4, type = "o", col = rainbow(ncol(sines)))
38463 maechler 108
matplot(sines, type = "b", pch = 21:23, col = 2:5, bg = 2:5,
109
        main = "matplot(...., pch = 21:23, bg = 2:5)")
27442 ripley 110
 
111
x <- 0:50/50
112
matplot(x, outer(x, 1:8, function(x, k) sin(k*pi * x)),
113
        ylim = c(-2,2), type = "plobcsSh",
114
        main= "matplot(,type = \"plobcsSh\" )")
115
## pch & type =  vector of 1-chars :
116
matplot(x, outer(x, 1:4, function(x, k) sin(k*pi * x)),
117
        pch = letters[1:4], type = c("b","p","o"))
118
 
48379 maechler 119
lends <- c("round","butt","square")
120
matplot(matrix(1:12, 4), type="c", lty=1, lwd=10, lend=lends)
121
text(cbind(2.5, 2*c(1,3,5)-.4), lends, col= 1:3, cex = 1.5)
122
 
30448 ripley 123
table(iris$Species) # is data.frame with 'Species' factor
27442 ripley 124
iS <- iris$Species == "setosa"
125
iV <- iris$Species == "versicolor"
126
op <- par(bg = "bisque")
61153 ripley 127
matplot(c(1, 8), c(0, 4.5), type =  "n", xlab = "Length", ylab = "Width",
27442 ripley 128
        main = "Petal and Sepal Dimensions in Iris Blossoms")
129
matpoints(iris[iS,c(1,3)], iris[iS,c(2,4)], pch = "sS", col = c(2,4))
130
matpoints(iris[iV,c(1,3)], iris[iV,c(2,4)], pch = "vV", col = c(2,4))
131
legend(1, 4, c("    Setosa Petals", "    Setosa Sepals",
132
               "Versicolor Petals", "Versicolor Sepals"),
133
       pch = "sSvV", col = rep(c(2,4), 2))
134
 
135
nam.var <- colnames(iris)[-5]
136
nam.spec <- as.character(iris[1+50*0:2, "Species"])
44243 ripley 137
iris.S <- array(NA, dim = c(50,4,3),
138
                dimnames = list(NULL, nam.var, nam.spec))
27442 ripley 139
for(i in 1:3) iris.S[,,i] <- data.matrix(iris[1:50+50*(i-1), -5])
140
 
61168 ripley 141
matplot(iris.S[, "Petal.Length",], iris.S[, "Petal.Width",], pch = "SCV",
61153 ripley 142
        col = rainbow(3, start = 0.8, end = 0.1),
27442 ripley 143
        sub = paste(c("S", "C", "V"), dimnames(iris.S)[[3]],
144
                    sep = "=", collapse= ",  "),
145
        main = "Fisher's Iris Data")
29354 ripley 146
par(op)
27442 ripley 147
}
148
\keyword{hplot}
149
\keyword{aplot}
150
\keyword{array}