Wrapper for a call to either axis or text, used to add axis labels to an existing plot.

add_axes(
  at,
  labels = NULL,
  side = 1,
  tick = F,
  line = NULL,
  cex = 1.25,
  degrees = NULL,
  xpd = NA,
  adj = NULL,
  ...
)

Arguments

at

The positions (x or y-axis) at which to add axis labels.

labels

Optional vector matching in length to at with user-defined labels.

side

The side of the plot at which to add axis labels, either...

  • 1 = bottom;

  • 2 = left;

  • 3 = top;

  • 4 = right.

tick

Logical; if TRUE draws tick marks at the specified positions.

line

The number of lines into the margin at which the axis line will be drawn. If degrees does not equal NULL, must be specified relative current plotting region (use par()$usr to get x and y-axis coordinates for plot region).

cex

Size of the text.

degrees

Number of degrees to rotate text (note results in a call to text() rather than axis()).

xpd

A logical value or NA. If FALSE, all plotting is clipped to the plot region. If TRUE, all plotting is clipped to the figure region, and if NA, all plotting is clipped to the device region.

adj

...

...

Additional parameters to be passed to either axis or text (if a value is provided for degrees).

Examples

# Create blank plot
blank_plot()
# Draw boundaries
hv_line(x = 0)
hv_line(y = 0)

# Add axes
add_axes(c(0, .5, 1), c("Start", "Middle", "End"))
add_axes(c(0, .5, 1), c("Bottom", "Middle", "Top"), side = 2)
add_axes(.5, "Title", side = 3, cex = 2)


# Create blank plot with custom margins
par(mar = rep(4, 4))
blank_plot()
# Draw boundaries
hv_line(x = 0:1)
hv_line(y = 0:1)

# Add rotated axes
add_axes(c(0, .5, 1), c("Start", "Middle", "End"),
  degrees = 45
)
add_axes(c(0, .5, 1), c("Start", "Middle", "End"),
  degrees = 45, side = 3
)
add_axes(c(0, .5, 1), c("Bottom", "Middle", "Top"),
  degrees = 45, side = 2
)
add_axes(c(0, .5, 1), c("Bottom", "Middle", "Top"),
  degrees = 45, side = 4
)