Low-level plotting commands



next up previous contents
Next: Interactive graphics functions Up: Graphical procedures Previous: Arguments to high-level

Low-level plotting commands

Sometimes the high-level plotting functions don't produce exactly the kind of plot you desire. In this case, low-level plotting commands can be used to add extra information (such as points, lines or text) to the current plot.

Some of the more useful low-level plotting functions are:


points(x,y)
lines(x,y)

Adds points or connected lines to the current plot. plot()'s type= argument can also be passed to these functions (and defaults to "p" for points() and "l" for lines().)


text(x, y, labels, ...)

Add text to a plot at points given by x, y. Normally labels is an integer or character vector in which case labels[i] is plotted at point (x[i], y[i]). The default is 1:length(x).

Note: This function is often used in the sequence
plot(x, y, type="n"); text(x, y, names)
The graphics parameter type="n" suppresses the points but sets up the axes, and the text() function supplies special characters, as specified by the character vector names for the points.


abline(a, b)
abline(h=y)
abline(v=x)
abline(lm.obj)

Adds a line of slope b and intercept a to the current plot. h=y may be used to specify y-coordinates for the heights of horizontal lines to go across a plot, and v=x similarly for the x-coordinates for vertical lines. Also lm.obj may be list with a $coefficients component of length 2 (such as the result of model-fitting functions,) which are taken as an intercept and slope, in that order.


polygon(x, y, ...)

Draws a polygon defined by the ordered vertices in (x,y). and (optionally) shade it in with hatch lines, or fill it if the graphics device allows the filling of figures.


legend(x,y, legend,...)

Adds a legend to the current plot at the specified position. Plotting characters, line styles, colours etc. are identified with the labels in the character vector legend. At least one other argument v (a vector the same length as legend) with the corresponding values of the plotting unit must also be given, as follows:

legend( ,angle=v)
Shading angles
legend( , density=v)
Shading densities
legend( ,fill=v)
Colours for filled boxes
legend( ,col=v)
Colours in which points or lines will be drawn
legend( ,lty=v)
Line styles
legend( ,pch=v)
Plotting characters (character vector)
legend( ,marks=v)
Plotting symbols, as obtained when using a numeric argument to pch= (numeric vector).

title(main,sub)

Adds a title main to the top of the current plot in a large font and (optionally) a sub-title sub at the bottom in a smaller font.


axis(side,...)

Adds an axis to the current plot on the side given by the first argument (1 to 4, counting clockwise from the bottom.) Other arguments control the positioning of the axis within or beside the plot, and tick positions and labels. Useful for adding custom axes after calling plot() with the axes=F argument.


Low-level plotting functions usually require some positioning information (e.g. x and y coordinates) to determine where to place the new plot elements. Coordinates are given in terms of user coordinates which are defined by the previous high-level graphics command and are chosen based on the supplied data.

Where x and y arguments are required, it is also sufficient to supply a single argument being a list with elements named x and y. Similarly a matrix with two columns is also valid input. In this way functions such as locator() (see below) may be used to specify positions on a plot interactively.



next up previous contents
Next: Interactive graphics functions Up: Graphical procedures Previous: Arguments to high-level



Erik Moledor
Tue Jan 31 21:02:18 EST 1995