Lorenz curve graphing tool & Gini coefficient calculator

March 5, 2011. Revised July 27, 2012

Enter incomes in the box on the left and click the Calculate button. The Lorenz curve (blue line) will be recalculated. The Gini index (being the Gini coefficient expressed as a percentage) and the Robin Hood index for the curve will also be recalculated.

Hover over a point on the curve to obtain information about it.


% of income
% of population

The Lorenz curve, the Gini index and the Robin Hood index

Lorenz curves represent the distribution of income in an economy. A point (x,y) on a Lorenz curve shows the percentage y of total income in an economy enjoyed by the poorest x% of the population.

The Gini index measures income inequality in an economy. It ranges from 0 (perfect income equality) to 100 (perfect income inequality). For example, Australia has a Gini index of 30.5 (2006) and the United States has a a Gini index of 45.0 (2007) [source: CIA Factbook].

The yellow line in the above graph is the line of perfect income equality. It is the Lorenz curve for an economy in which all incomes are equal.

The Gini index for a set of incomes is calculated from the associated Lorenz curve. It is equal to the area between that curve and the line of perfect income equality, scaled to a number between 0 and 100. The Gini coefficient is the Gini index expressed as a number between 0 and 1.

The Robin Hood index is another measure of income inequality. Like the Gini index, it ranges from 0 (perfect equality) to 100 (perfect inequality) and is calculated from the Lorenz curve associated with a given set of incomes. It is the maximum vertical distance between that curve and the line of perfect income equality. It is equal to the portion of total income that would have to be taken from the richer half of the population and given to the poorer half to bring the economy to income equality.

The spreadsheet

At the request of several students, I have created this Lorenz Curve Calculation Spreadsheet (XLSX, 0.1 MB). Enter incomes in the leftmost column and the sheet will calculate the points in the Lorenz curve. It also calculates the Gini index and the Robin Hood index.

R code

To calculate the Gini index using the R programming language, download and install R (it's free). Then install the reldist and xlsReadWrite packages. (Select Install package(s) from the Packages menu of the R Gui.)

Once that's done, save the data you want to calculate the Gini index of in the first column of a .xls spreadsheet (not .xlsx). Ensure that the column does not have a column header (i.e. the first row of the first column should be a number). Then run the following code, having modified it in accordance with the comments so that R can find your file.


# Set this to the directory containing your data file.
# Note that path uses "/" rather than "\".
path <- "C:/Users/User/Documents/R-working-directory/"

# Set this to the name of your data file. You may use a
# .csv file rather than an .xls.
file.name <- "gini.xls"

# Set the working directory

# Get the first column of the spreadsheet. Ensure that the first
# row of the first column is a number (rather than a row header).
vals <- read.xls(file=file.name, colNames=FALSE)[,1]
vals <- vals[-1]

# Those numbers have been read in as factors!
# Convert them to numbers.
vals <- as.numeric(levels(vals)[vals])

# Calculate the Gini coefficient
gc <- gini(vals)

print(paste("Gini Index:", gc*100," Gini Coefficient:", gc))

Calculation steps

Suppose that n incomes have been supplied. The Lorenz curve may then be described by n+1 points. Call these (x1,y1),...,(xn+1,yn+1).

To determine these points, first reorder the supplied incomes smallest to largest. Next, determine cumulative totals for the incomes. Call these c1,...,cn+1. We then have xi=100(i-1)/n and yi=100(ci/cn+1) for i=1,...,n+1.

Note, of course, that (x1,y1)=(0,0) and (xn+1,yn+1) = (100,100). Also note that cn+1 is the sum of all incomes.

The Gini index equals 100 + (100 - 2S)/n where S=y1+...+yn+1. This can easily be proved using basic high school mathematics. The Gini coefficient is the Gini index divided by 100.

The Robin Hood index is simply the maximum of xi-yi for i=1,...,n+1.

Credits: I created this tool using the Flot Javascript plotting library for jQuery.