annotate_ineq: Annotate ggplot2 chart with inequality metric

Description Usage Arguments References Examples

View source: R/annotate_ineq.R

Description

Adds text annotation to chart with any inequality measure from ineq::ineq Inequality measures include Gini, RS, Atkinson, Theil, Kol, var, square.var, entropy

Usage

1
2
3
4
5
6
7
8
9
annotate_ineq(
  data_ineq,
  x = 0.1,
  y = 0.95,
  decimals = 2,
  measure_ineq = "Gini",
  sep_ineq = ": ",
  ...
)

Arguments

data_ineq

Data to calculate the inequality metric on.

x

annotation x-axis position, defaults to 0.1.

y

annotation y-axis position, defaults to 0.95.

decimals

number of decimals to show, defaults to 2.

measure_ineq

Name of measure to use; defaults to Gini.

sep_ineq

text separator between annotation label and value.

...

any additional parameters to ggplot2::annotate().

References

Gini coefficient from Wikipedia

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
library(gglorenz)

ggplot(billionaires, aes(TNW)) +
    stat_lorenz() +
    annotate_ineq(billionaires$TNW)

ggplot(billionaires, aes(TNW)) +
    stat_lorenz(desc = TRUE) +
    geom_abline(linetype = "dashed") +
    theme_bw() +
    annotate_ineq(billionaires$TNW, measure_ineq = "RS", color = "red",
                  family = theme_get()$text[["family"]],
                  size = theme_get()$text[["size"]] / 2,
                  fontface = "italic")

gglorenz documentation built on July 1, 2020, 7:18 p.m.