Title: | Plotting Lorenz Curve with the Blessing of 'ggplot2' |
---|---|
Description: | Provides statistical transformations for plotting empirical ordinary Lorenz curve (Lorenz 1905) <doi:10.2307/2276207> and generalized Lorenz curve (Shorrocks 1983) <doi:10.2307/2554117>. |
Authors: | JJ Chen [aut, cre] , Hernando Cortina [aut] |
Maintainer: | JJ Chen <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.0.2.9000 |
Built: | 2024-11-05 05:27:58 UTC |
Source: | https://github.com/jjchern/gglorenz |
Adds text annotation to chart with any inequality measure from ineq::ineq Inequality measures include Gini, RS, Atkinson, Theil, Kol, var, square.var, entropy
annotate_ineq( data_ineq, freq_ineq = rep(1, length(data_ineq)), x = 0.1, y = 0.95, decimals = 2, measure_ineq = "Gini", sep_ineq = ": ", ... )
annotate_ineq( data_ineq, freq_ineq = rep(1, length(data_ineq)), x = 0.1, y = 0.95, decimals = 2, measure_ineq = "Gini", sep_ineq = ": ", ... )
data_ineq |
Data to calculate the inequality metric on. |
freq_ineq |
(optional) Frequency of each observation, defaults to 1, should be same length as data |
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(). |
Gini coefficient from Wikipedia
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") ## Not run: ggplot(freqdata, aes(x=value, n=freq)) + stat_lorenz() +annotate_ineq(freqdata$val, freqdata$freq) ## End(Not run)
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") ## Not run: ggplot(freqdata, aes(x=value, n=freq)) + stat_lorenz() +annotate_ineq(freqdata$val, freqdata$freq) ## End(Not run)
Contains 500 billionaires' name, country, industry, and total net worth. The data is collected in Feb. 8, 2018.
billionaires
billionaires
An object of class tbl_df
(inherits from tbl
, data.frame
) with 500 rows and 6 columns.
https://www.bloomberg.com/billionaires/
The package provides statistical transformations for plotting empirical ordinary Lorenz curve and generalized Lorenz curve.
JJ Chen
Provides ordinary Lorenz curve values for line plots
stat_lorenz( mapping = NULL, data = NULL, geom = "path", position = "identity", ..., desc = FALSE, show.legend = NA, inherit.aes = TRUE )
stat_lorenz( mapping = NULL, data = NULL, geom = "path", position = "identity", ..., desc = FALSE, show.legend = NA, inherit.aes = TRUE )
mapping |
Set of aesthetic mappings created by |
data |
The data to be displayed in this layer. There are three options: If A A |
geom |
which geom to use; defaults to " |
position |
Position adjustment, either as a string, or the result of a call to a position adjustment function. |
... |
Other arguments passed on to |
desc |
If FALSE, the default, the population is arranged in ascending order along the x-axis. If TRUE, the population is arranged in descending order. |
show.legend |
logical. Should this layer be included in the legends?
|
inherit.aes |
If |
stat_lorenz()
understands the following aesthetics:
x (required: wealth of individual, or set of individuals if n aesthetic used)
n (optional: frequency of given observation x)
library(gglorenz) ggplot(billionaires, aes(TNW)) + stat_lorenz() ggplot(billionaires, aes(TNW)) + stat_lorenz(desc = TRUE) + coord_fixed() + geom_abline(linetype = "dashed") + theme_minimal() ## Not run: ggplot(freqdata, aes(x=value, n=freq)) + stat_lorenz() ## End(Not run)
library(gglorenz) ggplot(billionaires, aes(TNW)) + stat_lorenz() ggplot(billionaires, aes(TNW)) + stat_lorenz(desc = TRUE) + coord_fixed() + geom_abline(linetype = "dashed") + theme_minimal() ## Not run: ggplot(freqdata, aes(x=value, n=freq)) + stat_lorenz() ## End(Not run)
Provides generalized Lorenz curve values for line plots
stat_lorenz_generalized( mapping = NULL, data = NULL, geom = "path", position = "identity", ..., show.legend = NA, inherit.aes = TRUE )
stat_lorenz_generalized( mapping = NULL, data = NULL, geom = "path", position = "identity", ..., show.legend = NA, inherit.aes = TRUE )
mapping |
Set of aesthetic mappings created by |
data |
The data to be displayed in this layer. There are three options: If A A |
geom |
which geom to use; defaults to " |
position |
Position adjustment, either as a string, or the result of a call to a position adjustment function. |
... |
Other arguments passed on to |
show.legend |
logical. Should this layer be included in the legends?
|
inherit.aes |
If |
library(gglorenz) ggplot(billionaires, aes(TNW)) + stat_lorenz_generalized()
library(gglorenz) ggplot(billionaires, aes(TNW)) + stat_lorenz_generalized()