Here is a statistic I have been curious about: how much money does the US give to other countries? This was a good chance to stretch my R and D3 chops.

I was only able to find machine-readable (well, if you can call a table in a PDF “machine-readable”) data for a few recent years. The radio buttons below control which year is being visualized.

First I went for the obvious visualization, a world map:

But to better see the rankings between countries, here is a simple bar chart:

(In the bar graph above, countries getting less than $20m are not shown, to keep the bars from getting too thin.)

Dev notes

A few notes about the development steps, so I can refer to this later:

  • Install rJava and Tabulizer:
  • Run R code to generate us-foreign-aid.json file
  • Install ogr2ogr and topojson
  • Get geo data and create map json
    • Download and unzip geo data
    • Run ogr2ogr on the .shp file: ogr2ogr -f "GeoJSON" subunits.json ne_50m_admin_0_map_units.shp
    • Run topojson on that file: topojson -o world-countries.json --id-property iso_a3 --properties name=name -- subunits.json
  • Write d3 code

Source code

Source of data