DescTools (version 0.99.15)

PlotLinesA: Plot Lines

Description

Plot the columns of one matrix against the columns of another. Adds a legend on the right at the endpoints of lines.

Usage

PlotLinesA(x, y, col = 1:5, lty = 1, lwd = 1, lend = par("lend"), 
           xlab = NULL, ylab = NULL, xlim = NULL, ylim = NULL, 
           cex = 1, cex.legend = 1, main = NULL, grid = TRUE, mar = NULL)

Arguments

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 (NAs) are allowed.
col
vector of colors. Colors are used cyclically.
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.
xlab, ylab
titles for x and y axes, as in plot.
xlim, ylim
ranges of x and y axes, as in plot.
cex, cex.legend
character expansion factor relative to current par("cex"). Can be set for matplot and for the legend text independently.
main
an overall title for the plot.
grid
logical adds an nx by ny rectangular grid to an existing plot.
mar
the margins of the plot.

Details

This function is rather a template, than a function. It wraps matplot to generate a lines plot and adds a rather sophisticated legend on the right side, while calculating appropriate margins. A grid option is included (as panel.first does not work in matplot). As in matplot, 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 vector, against which all columns of the other argument will be plotted.)

See Also

matplot, par

Examples

Run this code
m <- matrix(c(3,4,5,1,5,4,2,6,2), nrow = 3, 
            dimnames = list(dose = c("A","B","C"), 
                            age  = c("2010","2011","2012")))
                            
PlotLinesA(m, col=c(PalHelsana()), main="Dose ~ age_grp", lwd=3, ylim=c(1, 10))

Run the code above in your browser using DataCamp Workspace