Learn R Programming

pracma (version 1.8.8)

plotyy: Plotting Two y-Axes

Description

Line plot with y-axes on both left and right side.

Usage

plotyy(x1, y1, x2, y2, gridp = TRUE, box.col = "grey",
                       type = "l", lwd = 1, lty = 1,
                       xlab = "x", ylab = "y", main = "",
                       col.y1 = "navy", col.y2 = "maroon", ...)

Arguments

x1, x2
x-coordinates for the curves
y1, y2
the y-values, with ordinates y1 left, y2 right.
gridp
logical; shall a grid be plotted.
box.col
color of surrounding box.
type
type of the curves, line or points (for both data).
lwd
line width (for both data).
lty
line type (for both data).
xlab, ylab
text below and on the left.
main
main title of the plot.
col.y1, col.y2
colors to be used for the lines or points.
...
additional plotting parameters.

Value

  • Generates a graph, no return values.

Details

Plots y1 versus x1 with y-axis labeling on the left and plots y2 versus x2 with y-axis labeling on the right.

The x-values should not be too far appart. To exclude certain points, use NA values. Both curves will be line or point plots, and have the same line type and width.

See Also

plotrix::twoord.plot

Examples

Run this code
x  <- seq(0, 20, by = 0.01)
y1 <- 200*exp(-0.05*x)*sin(x)
y2 <- 0.8*exp(-0.5*x)*sin(10*x)

plotyy(x, y1, x, y2, main = "Two-ordinates Plot")

Run the code above in your browser using DataLab