Skip to contents

Displays a compositional bar chart.

Usage

# S4 method for CompositionMatrix
barplot(
  height,
  ...,
  order = NULL,
  decreasing = FALSE,
  groups = get_groups(height),
  horiz = TRUE,
  xlab = NULL,
  ylab = NULL,
  main = NULL,
  sub = NULL,
  ann = graphics::par("ann"),
  axes = TRUE,
  col = grDevices::hcl.colors(ncol(height), "viridis"),
  legend = list()
)

Arguments

height

A CompositionMatrix object.

...

Further parameters to be passed to graphics::barplot().

order

An integer vector giving the index of the column to be used for the ordering of the data.

decreasing

A logical scalar: should the sort order be increasing or decreasing?

groups

A factor in the sense that as.factor(groups) defines the grouping. If set, a matrix of panels defined by groups will be drawn.

horiz

A logical scalar. If FALSE, the bars are drawn vertically with the first bar to the left. If TRUE (the default), the bars are drawn horizontally with the first at the bottom.

xlab, ylab

A character vector giving the x and y axis labels.

main

A character string giving a main title for the plot.

sub

A character string giving a subtitle for the plot.

ann

A logical scalar: should the default annotation (title and x and y axis labels) appear on the plot?

axes

A logical scalar: should axes be drawn on the plot?

col

A vector of colors for the bar components.

legend

A list of additional arguments to be passed to graphics::legend(); names of the list are used as argument names. If NULL, no legend is displayed.

Value

barplot() is called for its side-effects: is results in a graphic being displayed (invisibly return height).

See also

Other plot methods: as_graph(), hist(), plot_logratio, plot()

Author

N. Frerebeau

Examples

## Data from Aitchison 1986
data("hongite")

## Coerce to compositional data
coda <- as_composition(hongite)

## Bar plot
barplot(coda, order = 2)


## Data from Day et al. 2011
data("kommos", package = "folio") # Coerce to compositional data
kommos <- remove_NA(kommos, margin = 1) # Remove cases with missing values
coda <- as_composition(kommos, groups = 1) # Use ceramic types for grouping
#> 1 qualitative variable was removed: date.

barplot(coda, order = 1)

barplot(coda, order = 1, horiz = FALSE)