Matplot Function is useful for quickly plotting multiple sets of observations from the same object, particularly from a matrix, on the same graph.
It Plots the columns of one matrix against the columns of another (which often is just a vector treated as 1-column matrix).
Syntax:
Matplot (x, y, type = “p”, lty = 1:5, lwd = 1, lend = par(“lend”), pch = NULL, col = 1:6, cex = NULL, bg = NA, xlab = NULL, ylab = NULL, xlim = NULL, ylim = NULL, log = “”, …, add = FALSE, verbose = get Option(“verbose”))
we will be looking into all properties used in the syntax.
We will be using the same previous real time scenario For plotting using Matplot ().
In previous example, Matrix Final data contains Financial Metrics as rows and Months as columns.
Here in this example iam printing the final data with matplot Function & the Final data is shown in plots pane.
If you want to transpose the matrix, Rows as columns and columns as Rows:
Simply write syntax as t(Final_data)
Let’s see how the output prints in console pane:
Here we can see the rows are interchanged to columns and columns are interchanged to rows in Console Pane.
Now plot the Transposed Matrix
As we have seen the plots pane, which is not good the data is not shown transparent.
To look data transparent, we must add additional properties.
Here in line 59 we are adding type,pch and col properties.
Plot pane:
Now plot pane looks better, Let’s look at the functionality of each properties use in Matplot () Function.
Arguments Used in matplot() Function:
1.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’ vector of ‘1:n’ is used. Missing values (‘NA’s) are allowed.
2.type
character string (length 1 vector) or vector of 1-character strings indicating the type of plot for each column of ‘y’, see ‘plot’ for all possible ‘type’s. The first character of ‘type’ defines the first plot, the second character the second, etc. Characters in ‘type’ are cycled through; e.g., ‘”pl”‘ alternately plots points and lines.
3.lty, lwd, lend
vector of line types, widths, and end styles. The first element 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.
4.pch
character string or vector of 1-characters or integers for plotting characters, see ‘points’. 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 lowercase and uppercase letters.
5.col
vector of colors. Colors are used cyclically.
6.cex
vector of character expansion sizes, used cyclically. This works as a multiple of ‘par(“cex”)’. ‘NULL’ is equivalent to ‘1.0’.
7.bg
vector of background (fill) colors for the open plot symbols given by ‘pch=21:25’ as in ‘points’. The default ‘NA’ corresponds to the one of the underlying function ‘plot.xy’.
8.xlab, ylab
titles for x and y axes, as in ‘plot’.
9.xlim, ylim
ranges of x and y axes, as in ‘plot’.
Let’s Practice sub setting Concept in my next post.