plot_lorenz: Lorenz Curve(s)

View source: R/plot_lorenz.R

plot_lorenzR Documentation

Lorenz Curve(s)

Description

This functions plots empirical Lorenz curves for one or several vectors.

Usage

plot_lorenz(
  dat,
  pal_curves = "npg",
  title = ifelse(is.numeric(dat), "Lorenz Curve", "Lorenz Curves"),
  leg.txt = NULL,
  legend = "topleft",
  hover = FALSE
)

Arguments

dat

Numeric vector, or several such vectors organized into a list, optionally named. May also be a data frame of such vectors, however in that case each must be of equal length. Data may include negative values, but if so a warning will be issued to proceed with caution.

pal_curves

String specifying the color palette to use when plotting multiple vectors. Options include "ggplot", all qualitative color schemes available in RColorBrewer, and the complete collection of ggsci palettes. Alternatively, a character vector of colors with length equal to the number of vectors in dat.

title

Optional plot title.

leg.txt

Optional legend title.

legend

Legend position. Must be one of "bottom", "left", "top", "right", "bottomright", "bottomleft", "topleft", or "topright".

hover

Show vector name by hovering mouse over Lorenz curve? If TRUE, the plot is rendered in HTML and will either open in your browser's graphic display or appear in the RStudio viewer.

Details

The Lorenz curve of a distribution plots its cumulative proportion of observations against its cumulative proportion of values. The extent to which the curve sags below the straight diagonal line indicates the variable's degree of inequality. This is measured by the Gini coefficient, which represents the ratio of the area between the line of perfect equality and the distribution's Lorenz curve to the total area under the diagonal line. The statistic has range [0, 1] for non-negative data, with higher coefficients corresponding to more unequal distributions.

Lorenz curves are common in economics, where Gini coefficients are often used to measure the inequality of national income distributions. They also have several omic applications, e.g. to visualize the degree of biodiversity in a microbiome, or the spread of RNA-sequencing counts across libraries.

Examples

x <- runif(100)
plot_lorenz(x)

X <- list("Uniform" = runif(100),
          "Poisson" = rpois(200, lambda = 5))
plot_lorenz(X)


dswatson/bioplotr documentation built on March 3, 2023, 9:43 p.m.