# Racing bar charts

Jiro‘s Pick this week is barChartRace by Eiji Konaka.

This an example of a nice outcome that spawned from a community discussion. It all started with this tweet.

Translation: “Is there a simple MATLAB function that could easily create this animation? I want it…”

I learned that this type of animation, where the bars switch places based on the order, is called Bar Chart Race.

My colleague, Michio, replied to the tweet saying that you can do some graphical updates with the barh function.

Michio created a sample, which he explained in a Japanese technical community site (in Japanese). This inspired Eiji to create his barChartRace, and he also wrote about it here (in Japanese).

So, let’s see this in action. I made some modifications to Eiji’s function to include an option to display the time stamp in the title, and to reverse the order of the bars. Here is an example of the FIFA World Rankings from 1993 to 2018. The rankings are based on the data from https://www.fifa.com/fifa-world-ranking/ranking-table/men/

load data y time countries

Opt.xTickLabelStrs = countries;
Opt.outFileName='barchartrace_outFile.gif';
Opt.xLabelStr='Ranking';
Opt.yLabelStr='Country';
Opt.titleStr='FIFA World Ranking';
Opt.faceColor=[0,0,1];
Opt.time = time;
Opt.yDir = 'reverse';

barChartRace(y, Opt)


It was great to see the communication and collaboration that happened over social media. By the way, Michio went ahead and extended his version of the bar chart race to include a few other options. You can find it here.