Learn R Programming

plotrix (version 2.6-1)

twoord.plot: Plot with two ordinates

Description

Two sets of values are displayed on the same plot with different ordinate scales on the left and right.

Usage

twoord.plot(lx,ly,rx,ry,data=NULL,xlim=NULL,lylim=NULL,rylim=NULL,
 mar=c(5,4,4,4),lcol=1,rcol=2,xlab="",ylab="",rylab="",lpch=1,rpch=2,
 type="b",halfwidth=0.4,...)

Arguments

lx,ly,rx,ry
y and optional x values for the plot
data
an optional data frame from which to obtain the above values
xlim
optional x limits as in plot
lylim,rylim
optional y limits for the left and right axes respectively
mar
optional margin adjustment, defaults to c(5,4,4,4)
lcol,rcol
colors to distinguish the two sets of values
xlab,ylab
axis labels as in plot
rylab
label for the right axis
lpch,rpch
plot symbols to distinguish the two sets of values
type
as in plot
halfwidth
Half the width of the bars in user units. The bars are centered on successive integers if no x values are supplied.
...
additional arguments passed to axis.

Value

  • nil

Details

twoord.plot automates the process of displaying two sets of values that have different ranges on the same plot. It is principally useful in illustrating some relationship between the values across the observations. It is assumed that the lx and rx values are at least adjacent, and probably overlapping. It is best to pass all the arguments lx, ly, rx, ry, but the function will attempt to substitute sensible x values if one or two are missing.

If at least one of the type arguments is "bar", bars will be plotted instead of points or lines. It is best to plot the bars first (i.e. relative to the left axis) if the other type is points or lines, as the bars will usually obscure at least some of the points or lines. Using NA for the color of the bars will partially correct this. If both types are to be bars, remember to pass somewhat different x values or the bars will be overlaid.

See Also

plot

Examples

Run this code
twoord.plot(2:10,seq(3,7,by=0.5)+rnorm(9),
  1:15,rev(60:74)+rnorm(15),xlab="Sequence",
  ylab="Ascending values",rylab="Descending values",
  main="Plot with two ordinates - points and lines")
 twoord.plot(2:10,seq(3,7,by=0.5)+rnorm(9),
  1:15,rev(60:74)+rnorm(15),xlab="Sequence",
  ylab="Ascending values",rylab="Descending values",
  main="Plot with two ordinates - bars on the left",
  type=c("bar","l"),lcol=3,rcol=4)
 twoord.plot(2:10,seq(3,7,by=0.5)+rnorm(9),
  1:15,rev(60:74)+rnorm(15),xlab="Sequence",
  ylab="Ascending values",rylab="Descending values",
  main="Plot with two ordinates - bars on the right",
  type=c("b","bar"),lcol=2,rcol=NA,halfwidth=0.2)

Run the code above in your browser using DataLab