niceLabels: Nice Labels

View source: R/main.R

niceLabelsR Documentation

Nice Labels

Description

Generates a nice vector of labels by suppressing labels at certain positions. If a labelStep is given, only every labelStep-th label is considered. If a vector labpos of label positions and a minimum distance mindist of labels is given, it is guaranteed that the distance between labels to be shown is at least mindist.

Usage

niceLabels(label, labelstep = NULL, labelpos = NULL, mindist = 1, offset = 0)

Arguments

label

vector of labels

labelstep

step width in which labels are to be printed, e.g. labelStep = 2 is used for plotting every second label.

labelpos

label positions

mindist

minimum distance between labels

offset

offset by which the index of the first remaining label (default: 1) is shifted. Default: 0, i.e. the labels at indices 1, 1 + 1*labelstep, 1 + 2*labelstep, etc. remain. Offset = 1: the labels at indices 2, 2 + 1*labelstep, 2 + 2*labelstep, etc. remain.

Examples

  
  x <- matrix(1:12, nrow = 3)
  
  names.arg <- rep(1:4, each = 3)
  
  mybarplot <- function(x, ...) {
    barplot(x, horiz = TRUE, las = 1, beside = TRUE, ...)
  }
    
  mybarplot(x, names.arg = names.arg)
  mybarplot(x, names.arg = niceLabels(names.arg, labelstep = 3))
  mybarplot(x, names.arg = niceLabels(names.arg, labelstep = 3, offset = 1))
  mybarplot(x, names.arg = niceLabels(names.arg, labelstep = 3, offset = 2))
  

KWB-R/kwb.plot documentation built on Oct. 2, 2023, 10:16 p.m.