Ryan C Briggs
01.11.2008

Circle Plot Code

Before you even start reading this, you deserve a warning. This post exists mostly so I can keep track of my code and ideas. I am putting it online because it seems conceivable that some one on the internet might find it useful.

At the bottom of this post, you can download the latest version of the processing code that I used to create my circle plots. It is also the first program I have written since high school, and it still needs a lot of work. That said, it does most of what I need it to do. It is only 72 lines long and I tried to keep it readable, so hopefully you can see what I am trying to do pretty quickly.

To use it, you first need to download processing and download my sketch. The program relies on two external files. First, you need to load a font into the sketch. The font that I use is called Silkscreen. It is free to download and use. Second, you need to create a .csv file with your data, name it “data.csv” and add it to your sketch. The variables in the file control (in order): country name, position on x axis, position on y axis, size of the circle, and colour (blue to red).

The program is incomplete. The biggest problems are:

  • All variables in the .csv file (except the country name) must be scaled 0-100 outside of the program (100 is the max value and 0 is the min). I have been doing this in SPSS. This means that all of the positioning is relative, not absolute.
    • The program needs a way to internally scale the raw numbers so that SPSS is not needed.
    • The program needs a way to decouple the x and y values from the size of the sketch, which could allow for plotting raw numbers without scaling them against each other.
  • The font doesn’t scale with the image size. A larger font should be used when the image gets to a certain size.
    • A simple if statement will fix this, but I wanted to fix the previous problems first because they might complicate this fix.
  • The output (in the window that appears when you run the program) doesn’t match the image that is produced and saved in the sketch’s folder. The image is there, but the output window doesn’t show it.
    • This only started happening after I downloaded the most recent beta, version 0154.
  • I would like a way to show changes over time, perhaps by showing a circle for each year, starting with high transparency, and then making the circles less transparent as they move through time.
    • This would involve changing the arrays and I haven’t thought it through yet. I would probably add a year variable to the end of each line in the .csv file.
  • It might be nice to be able to colour each circle after a region, so that all of Europe, for example, was the same colour. It would make comparisons easier.
    • If I did this then the current colour scaling code would need to be either replaced to added on to.
    • This might also necessitate adding another variable, because the current colour variable must be scaled 0-100 and links to an attribute that exists for each circle.

    The code was last updated on Nov 1, 2008.

    Download the code, as a processing file, here.

    20.10.2008
    Here is another image I made with processing (and pixelmator). The x-axis is population density. The y-axis is GDP per capita. The bottom left holds the low values. The colour of each circle is determined by the country’s Polity IV score (democracy score). Blue is more democratic and red is more authoritarian. The size of each circle is determined by the size of the country’s population.
The inlay blows up the chaos of the bottom left corner and scales down the radius of the circles to improve visibility. The sizes and placement of the circles within the inlay are correct relative to each other.
Click the image to download the much larger version (2000x2000 px).

    Here is another image I made with processing (and pixelmator). The x-axis is population density. The y-axis is GDP per capita. The bottom left holds the low values. The colour of each circle is determined by the country’s Polity IV score (democracy score). Blue is more democratic and red is more authoritarian. The size of each circle is determined by the size of the country’s population.

    The inlay blows up the chaos of the bottom left corner and scales down the radius of the circles to improve visibility. The sizes and placement of the circles within the inlay are correct relative to each other.

    Click the image to download the much larger version (2000x2000 px).

    19.10.2008
    I recently started playing around with Processing and this is the result of my first experiment. I wanted to generate a picture that would show general trends in 4 variables across many countries in an intuitive way. I looked at 43 countries in sub-Saharan Africa.
The variable selection (this time) was almost random. The x-axis is the number average number of children in a family in 2003. It ranges from 2 to 8. The y-axis is the total amount of ODA in 2003, ranging from 10 million to 5 billion. The colour is tied to the Polity IV scores for each country: blue is more democratic, red is less. Finally, the size of the circle is the population size. Nigeria is the huge circle. A few countries were too small to show up and labels were not generated for them.
The Democratic Republic of the Congo is the circle all alone at the top. Its ODA in 2003 was apparently 5 billion. That seems way too big to me, but debt forgiveness (and other things you may not think of as aid) are included in ODA. Still, its placement may be due to an error in the data set.
Click the picture to get a higher quality version of the picture. Kottke made the font. I would love suggestions or criticism. I will post the code after I clean it up.

    I recently started playing around with Processing and this is the result of my first experiment. I wanted to generate a picture that would show general trends in 4 variables across many countries in an intuitive way. I looked at 43 countries in sub-Saharan Africa.

    The variable selection (this time) was almost random. The x-axis is the number average number of children in a family in 2003. It ranges from 2 to 8. The y-axis is the total amount of ODA in 2003, ranging from 10 million to 5 billion. The colour is tied to the Polity IV scores for each country: blue is more democratic, red is less. Finally, the size of the circle is the population size. Nigeria is the huge circle. A few countries were too small to show up and labels were not generated for them.

    The Democratic Republic of the Congo is the circle all alone at the top. Its ODA in 2003 was apparently 5 billion. That seems way too big to me, but debt forgiveness (and other things you may not think of as aid) are included in ODA. Still, its placement may be due to an error in the data set.

    Click the picture to get a higher quality version of the picture. Kottke made the font. I would love suggestions or criticism. I will post the code after I clean it up.

    02.10.2008

    President Koroma's Speech

    Sunday night I saw President Koroma of Sierra Leone speak at American University. His speech was mostly focused on development issues in Sierra Leone and I thought some readers might find it interesting.

    President Koroma outlined his priorities as follows:

    1. Energy
    2. Agriculture & Infrastructure
    3. Tourism & Mining

    His energy policy had two goals. First, providing a reliable amount of energy to Freetown by completing the Bumbuna dam and the transmission lines. Second, by testing and implementing pilot projects involving mini-dams to provide power to rural areas.

    The agricultural policies were mentioned second. The end goal of the policies was to stop being a rice importer by 2011. This would require increasing domestic rice production by 500 000 metric tons. Nor surprisingly, Sierra Leone’s rice production fell drastically between 1990 and 2000. President Koroma vaguely identified two ways of increasing production: increasing investment in agriculture and “reviewing the land tenure system.”

    Tourism and mining were mentioned as third tier priorities and ways of increasing foreign exchange. The plan for increasing tourism centered around building better hotels and improving the country’s image. The government is also apparently reviewing mining licenses, although I do not know exactly what that means.

    President Koroma included passing references to corruption “as a cancer of society” and said that education “was the most important investment in our future”. He finished by stating that there would be elections within 36 months and that if he lost he would step down without a hassle. He then answered questions from diaspora Sierra Leonians in the audience, one of which I will include:

    • Q: What is your government doing to prevent FGM?
    • A: FGM is a sensitive issue in our country. We (Sierra Leonians) need a solution that is acceptable both to the women of Sierra Leone and the international community. This issue is currently under review.

    22.09.2008
    I am way out of my (tiny) area of expertise here, but it occurred to me yesterday while reading this article by the Globe and Mail that there is a strange divide between typically “right” and “left” parties that I haven’t thought about before.
The general idea is that “left” parties (Democrats), tend to promote economic policies that focus on the collective. They look at “correcting” economic outcomes, often by redistributing wealth. This stems from a focus on the group, not on individual economic actors. When it comes to lots of other policies (what I erroneously called “social policies” in the table), left wing parties seem to focus more on individuals. Torture is always wrong because it violates individual rights. Gay marriage is good because of the rights of individuals (at least in Canada).
Conservatives, (or the “right”, or Republicans) have the opposite focus. Torture may be okay in some situations because the security of the group depends on it. The same argument can be made for wiretaps or detentions without trial or what have you. Similarly, the morals of the group are seen to be at stake in the gay marriage debate. When it comes to economics, however, the individual is king. Thatcher, in one great quote that I am paraphrasing said that “there is no such thing as society”.
I have no great conclusions with this, just some open pondering. Have I belatedly stumbled upon something everyone already knows? Anyone know where I can read more on this? Discussion is on twitter.

    I am way out of my (tiny) area of expertise here, but it occurred to me yesterday while reading this article by the Globe and Mail that there is a strange divide between typically “right” and “left” parties that I haven’t thought about before.

    The general idea is that “left” parties (Democrats), tend to promote economic policies that focus on the collective. They look at “correcting” economic outcomes, often by redistributing wealth. This stems from a focus on the group, not on individual economic actors. When it comes to lots of other policies (what I erroneously called “social policies” in the table), left wing parties seem to focus more on individuals. Torture is always wrong because it violates individual rights. Gay marriage is good because of the rights of individuals (at least in Canada).

    Conservatives, (or the “right”, or Republicans) have the opposite focus. Torture may be okay in some situations because the security of the group depends on it. The same argument can be made for wiretaps or detentions without trial or what have you. Similarly, the morals of the group are seen to be at stake in the gay marriage debate. When it comes to economics, however, the individual is king. Thatcher, in one great quote that I am paraphrasing said that “there is no such thing as society”.

    I have no great conclusions with this, just some open pondering. Have I belatedly stumbled upon something everyone already knows? Anyone know where I can read more on this? Discussion is on twitter.

    07.09.2008

    Worth reading:

    Forget flag pins. Ask about assaults on the Constitution 

    A good summary on the CF that the US is in and some good questions that the presidential nominees need to answer.

    Restating the Case Against Aid

    A decent summary of a few recent articles on the importance of trade and governance to Africa’s development. I don’t agree with all of the points on aid and Asian investment, but the presentation is good nonetheless.

    Brave New World of Digital Intimacy

    Describes what I like about twitter far more eloquently than I could.

    27.08.2008

    Backtype

    A while back I had this idea of using twitter for blog comments. If anyone thought this idea was interesting, you will want to check out Backtype. It is based on a similar (but superior) idea and seems to have been implemented well. Great job guys.

    ← older posts