|
| 1 | +#' @title Add an axis to a plot without labels as the default |
| 2 | +#' |
| 3 | +#' @description A wrapper function for \code{\link[base]{axis}} |
| 4 | +#' with three changes. |
| 5 | +#' |
| 6 | +#' 1. \code{labels = FALSE} is now the default. |
| 7 | +#' 2. \code{tck} has been added as an argument, which is used to specify the size of the tick mark. |
| 8 | +#' 3. \code{minor} has been added as an argument. Used to add minor (i.e., smaller) tickmarks equally between the first axis. |
| 9 | + |
| 10 | +#' |
| 11 | +#' @param side an integer specifying which side of the plot the axis is to be drawn on. The axis is placed as follows: 1=below, 2=left, 3=above and 4=right. |
| 12 | +#' |
| 13 | +#' @param at The points at which tick-marks are to be drawn. Non-finite (infinite, NaN or NA) values are omitted. By default (when NULL) tickmark locations are computed using \code{\link[graphics]{axTicks}}. |
| 14 | +#' |
| 15 | +#' @param labels Set to \code{FALSE}. See \code{\link[graphics]{axis}}. |
| 16 | +#' |
| 17 | +#' @param tick See \code{\link[graphics]{axis}}. |
| 18 | +#' |
| 19 | +#' @param line See \code{\link[graphics]{axis}}. |
| 20 | +#' |
| 21 | +#' @param pos See \code{\link[graphics]{axis}}. |
| 22 | +#' |
| 23 | +#' @param outer See \code{\link[graphics]{axis}}. |
| 24 | +#' |
| 25 | +#' @param font See \code{\link[graphics]{axis}}. |
| 26 | +#' |
| 27 | +#' @param lty See \code{\link[graphics]{axis}}. |
| 28 | +#' |
| 29 | +#' @param lwd See \code{\link[graphics]{axis}}. |
| 30 | +#' |
| 31 | +#' @param lwd.ticks See \code{\link[graphics]{axis}}. |
| 32 | +#' |
| 33 | +#' @param col See \code{\link[graphics]{axis}}. |
| 34 | +#' |
| 35 | +#' @param col.ticks See \code{\link[graphics]{axis}}. |
| 36 | +#' |
| 37 | +#' @param hadj See \code{\link[graphics]{axis}}. |
| 38 | +#' |
| 39 | +#' @param padj See \code{\link[graphics]{axis}}. |
| 40 | +#' |
| 41 | +#' @param gap.axis See \code{\link[graphics]{axis}}. |
| 42 | +#' |
| 43 | +#' @param tck The length of tick marks as a fraction of the smaller of the width or height of the plotting region. If tck >= 0.5 it is interpreted as a fraction of the relevant side, so if tck = 1 grid lines are drawn. The default setting is (tck = -0.025). |
| 44 | +#' |
| 45 | +#' @param minor Whether or not to add smaller tick marks spaced equally between the larger tickmarks specified by the at argument. Tick length is set to \code{tck * 0.5}. |
| 46 | +#' |
| 47 | +#' @param ... Other graphical parameters that may apply to \code{\link[graphics]{axis}}. |
| 48 | +#' |
| 49 | +#' |
| 50 | +#' |
| 51 | +#' @examples |
| 52 | +#' \dontrun{ |
| 53 | +#' blank( |
| 54 | +#' xlim = c(0,50), |
| 55 | +#' ylim = c(0,100), |
| 56 | +#' bty ="l" |
| 57 | +#' ) |
| 58 | +#' |
| 59 | +#' axis_blank(1, at = seq(0,50,10)) |
| 60 | +#' axis_blank(2, at = seq(0,100,20)) |
| 61 | +#' |
| 62 | +#' } |
| 63 | +#' |
| 64 | +#' @export |
| 65 | +axis_blank <- function(side, at = NULL, labels = FALSE, tick = TRUE, line = NA, |
| 66 | + pos = NA, outer = FALSE, font = NA, lty = "solid", |
| 67 | + lwd = 1, lwd.ticks = lwd, col = NULL, col.ticks = NULL, |
| 68 | + hadj = NA, padj = NA, gap.axis = NA, ..., tck = -0.02, minor = TRUE){ |
| 69 | + if(!is.numeric(side)){ |
| 70 | + stop("side must be numeric. 1=below, 2=left, 3=above and 4=right.") |
| 71 | + } |
| 72 | + if(is.null(at)){ |
| 73 | + is_logged <- ifelse(side %in% c(1,3), par("xlog"), par("ylog")) |
| 74 | + |
| 75 | + at <- axTicks(side = side, log = is_logged) |
| 76 | + } |
| 77 | + axis(side = side, at = at, labels = labels, tick = tick, line = line, pos = pos, |
| 78 | + outer = outer, font = font, lty = lty, lwd = lwd, lwd.ticks = lwd, col = col, |
| 79 | + col.ticks = col.ticks, hadj = hadj, padj = padj, gap.axis = gap.axis, |
| 80 | + tck = tck, ...) |
| 81 | + if(minor){ |
| 82 | + smaller_seq <- seq(at[1], max(at), (at[2] - at[1])/2) |
| 83 | + axis(side = side, at = smaller_seq, labels = labels, tick = tick, line = line, pos = pos, |
| 84 | + outer = outer, font = font, lty = lty, lwd = lwd, lwd.ticks = lwd, col = col, |
| 85 | + col.ticks = col.ticks, hadj = hadj, padj = padj, gap.axis = gap.axis, |
| 86 | + tck = tck/2, ...) |
| 87 | + |
| 88 | + } |
| 89 | +} |
0 commit comments