stringplot: Plot for Distribution of Categorical Variables

View source: R/stringplot.R

stringplotR Documentation

Plot for Distribution of Categorical Variables

Description

Alternative plot to display distribution of categorical variables. The function stringplot() produces a plot of frequencies for classes of categorical variables and is similar to box-and-whisker plots but it may be interpreted as histograms.

This plot function is offered as an alternative to boxplot() for categorical (ordinal) variables and single string piles should be interpreted as histograms. To plot single string piles the function strp() is called internally. Alternatively shadowplot() or a combination of both can be used.

The function strp() calculates the frequency of single values in the vector x and displays them in a string pile by using the function segments(). The resulting pile indicates by the with of strings the relative frequency of the respective values in the input vector. This plot function is offered as an alternative to boxplot() for categorical and ordinal data and should be interpreted as an histogram.

Usage

strp(x, lwd = 1, maxwidth = 1, col = "black", at)

stringplot(x, ...)

## Default S3 method:
stringplot(x, ...)

## S3 method for class 'numeric'
stringplot(
  x,
  lwd = 1,
  maxwidth = 1,
  col = "black",
  at,
  bty = "n",
  xaxt = "n",
  ylim,
  xlab = "",
  ylab = "classes",
  ...
)

## S3 method for class 'data.frame'
stringplot(
  x = data.frame(),
  what,
  by,
  at,
  col,
  lwd = 2,
  maxwidth = 1,
  xlab = "",
  ylab = "classes",
  xlim,
  ylim,
  xaxt = "s",
  ...
)

## S3 method for class 'formula'
stringplot(formula, data = data.frame(), ...)

Arguments

x

Either an integer vector or a data frame.

lwd

Line width for strings (see par()).

maxwidth

Magnification factor for line width.

col

Colour for strings.

at

Position of string piles in existing plot.

...

Further arguments to be passed among methods.

bty

Type of box around plotting area (see par()).

xaxt

Specification of x axis type (see par()).

xlab

Labels for x axis (see par()).

ylab

Labels for y axis (see par()).

what

Name of the variable to be plotted (in data frame method).

by

Name of the splitting variable (in data frame method).

xlim, ylim

Limits for x and y axes (see par()).

formula

A formula for plotting.

data

Data frame containing the vectors to be plotted.

Author(s)

Miguel Alvarez (malvarez@uni-bonn.de).

References

Beuel S, Alvarez M, Amler E, Behn K, Kotze D, Kreye C, Leemhuis C, Wagner K, Willy DK, Ziegler S, Becker M (2016). A rapid assessment of anthropogenic disturbances in East African wetlands. Ecological Indicators 67: 684-692.

See Also

strp, shadowplot.

stringplot(), error_bars().

Examples

data(WHscores)

## Hydrology scores per land use
stringplot(WET_hydro ~ Landuse,
  data = WHscores, xlab = "Land uses",
  ylab = "WET-health scores", main = "Hydrology module", lwd = 3
)

## Adding tendencies
Tendency <- aggregate(WET_hydro ~ Landuse, WHscores, median)
with(Tendency, {
  lines(1:4, WET_hydro, lty = 2)
  points(1:4, WET_hydro, pch = 21, bg = "white", cex = 1.5)
})

#' ## Strings overlaid to box and whisker plot (note the bimodal distribution)
boxplot(WHscores$WET_veg, border = "grey", col = "palegreen")
strp(WHscores$WET_veg, lwd = 4, at = 1)


kamapu/Lexiguel documentation built on July 29, 2022, 7:52 p.m.