

matplot {base}                               R Documentation

_P_l_o_t _C_o_l_u_m_n_s _o_f _M_a_t_r_i_c_e_s

_D_e_s_c_r_i_p_t_i_o_n_:

     Plot the columns of one matrix against the columns of
     another.

_U_s_a_g_e_:

     matplot(x, y, type = "p", lty = 1:5, lwd = 1, pch = NULL, col = 1:6,
             xlab = NULL, ylab = NULL, xlim = NULL, ylim = NULL,
             ..., add = FALSE)
     matpoints(x, y, lty = 1:5, lwd = 1, pch = NULL, col = 1:6)
     matlines(x, y, lty = 1:5, lwd = 1, pch = NULL, col = 1:6)

_A_r_g_u_m_e_n_t_s_:

     x,y: vectors or matrices of data for plotting.  The
          number of rows should match.  If one of them are
          missing, the other is taken as `y' and an `x' vec-
          tor of `1:n' is used.  Missing values (`NA's) are
          allowed.

    type: character string, telling which type of plot
          (`"p"', points; `"l"', lines; `"b"', both; `"o"',
          overplotted both; `"n"', none; or `"h"', high-den-
          sity) should be done for each column of `y'.  The
          first character of `type' defines the first plot,
          the second character the second, etc.  Characters
          in `type' are cycled through; e.g., `"pl"' alter-
          nately plots points and lines.

 lty,lwd: vector of line types and widths.  The first ele-
          ment is for the first column, the second element
          for the second column, etc., even if lines are not
          plotted for all columns. Line types will be used
          cyclically until all plots are drawn.

     pch: character string (length 1 vector) or vector of
          1-character strings for plotting-characters.  The
          first character is the plotting-character for the
          first plot, the second for the second, etc.  The
          default is the digits (1 through 9, 0) then the
          letters.

     col: vector of colors.  Colors are used cyclically.

xlim, ylim: ranges of x and y axes, as in `plot'.

xlab, ylab: titles for x and y axes, as in `plot'.

     ...: Graphical parameters (see `par') may also be sup-
          plied as arguments to this function.  In addition,
          the high-level graphics control arguments
          described under `par' and the arguments to `title'
          may be supplied to this function.

     add: logical.  If `TRUE', plots are added to current
          one, using `points' and `lines'.

 verbose: logical.  If `TRUE', write one line of what is
          done.

_D_e_t_a_i_l_s_:

     Points involving missing values are not plotted.

     The first column of `x' is plotted against the first
     column of `y', the second column of `x' against the
     second column of `y', etc.  If one matrix has fewer
     columns, plotting will cycle back through the columns
     again.  (In particular, either `x' or `y' may be a vec-
     tor, against which all columns of the other argument
     will be plotted.)

     Because plotting symbols are drawn with lines and
     because these functions may be changing the line style,
     you should probably specify `lty=1' when using plotting
     symbols.

_S_i_d_e _E_f_f_e_c_t_s_:

     Function `matplot' generates a new plot; `matpoints'
     and `matlines' add to the current one.

_S_e_e _A_l_s_o_:

     `plot', `points', `lines', `matrix', `par'.

_E_x_a_m_p_l_e_s_:

     matplot((-4:5)^2, main = "Quadratic")
     sines <- outer(1:20, 1:4, function(x, y) sin(x / 20 * pi * y))
     matplot(sines, type = "o", col = rainbow(ncol(sines)))

     x <- 0:100/100
     matplot(x, outer(x, 1:8, function(x, k) sin(k * pi * x)),
             type = "l", col = 1:8, ylim = c(-2,2))

     data(iris)                  # is data.frame with  `Species' factor
     table(iris$Species)
     iS <- iris$Species == "setosa"
     iV <- iris$Species == "versicolor"
     op <- par(bg = "bisque")
     matplot(c(1, 8), c(0, 4.5), type= "n", xlab = "Length", ylab = "Width",
             main = "Petal and Sepal Dimensions in Iris Blossoms")
     matpoints(iris[iS,c(1,3)], iris[iS,c(2,4)], pch = "sS", col = c(2,4))
     matpoints(iris[iV,c(1,3)], iris[iV,c(2,4)], pch = "vV", col = c(2,4))
     legend(1, 4, c("    Setosa Petals", "    Setosa Sepals",
                    "Versicolor Petals", "Versicolor Sepals"),
            pch = "sSvV", col = rep(c(2,4), 2))

     nam.var <- colnames(iris)[-5]
     nam.spec <- as.character(iris[1+50*0:2, "Species"])
     iris.S <- array(NA, dim = c(50,4,3), dimnames = list(NULL, nam.var, nam.spec))
     for(i in 1:3) iris.S[,,i] <- data.matrix(iris[1:50+50*(i-1), -5])

     matplot(iris.S[,"Petal.Length",], iris.S[,"Petal.Width",], pch="SCV",
             col = rainbow(3, start = .8, end = .1),
             sub = paste(c("S", "C", "V"), dimnames(iris.S)[[3]],
                         sep = "=", collapse= ",  "),
             main = "Fisher's Iris Data")

