Visualizing commodity trade in mercury with an interactive 3D globe

It was almost TOO easy.

A data visualization app called Flourish has been getting a bit of buzz recently, so I decided to check it out. I noticed a slick existing template using 3D WebGL for illustrating global trade flows. I have a perfect dataset for that!

Our recently published UN Environment Global Mercury Supply, Trade and Demand Report contains data pulled from the UN Comtrade database on global mercury trade in 2008 and 2015. A few hours of data munging and it was ready to go into the template. Flourish also has a story feature which allows you to walk viewers through an interactive graphic. Sort of like a story map in GIS. Here is the result:

2018-06-27_140608

Click on the image to view the interactive story

A link to the graphic itself (without the story) is here.

One word of caution. No matter how slick a graphic looks and performs, it’s only worth as much as the underlying data. In this case, we know that UN Comtrade data for mercury has some serious flaws, including errors and missed reporting by importing and exporting countries, to say nothing of illegal trade (we discuss these issues in the report). Nevertheless we believe the data is still useful in providing an overview of global trade. But please keep the limitations in mind.

Advertisements

Making an Animated GIF Map to Show Progress of the Adoption of the Minamata Convention

If you’ve been anywhere near the internets recently you know that animated gifs are ubiquitous. Never one to miss a trend, I decided to make an animated gif – of a map of course. Actually, gifs can be a good way to show movement in maps and charts. Here are some nice examples and tips.

The animation shows which countries are Parties to the Minamata Convention. They appear in order of ratification.

minamata large loop

The inspiration and method for this animation came from Alasdair Rae:

Alasdair wrote a useful tutorial on how to use QGIS to create amimated map “geogifs”. I’d been looking for an excuse to play around with QGIS (a free desktop GIS application) for a while. In general I found QGIS quite easy to use and feature-rich. My only complaint is not limited to QGIS but applies to all graphical user interface apps. While they are much easier to get started with, they lack the ability to create a reproducible workflow. If I had to make the map again from another dataset I’d have to remember and recreate all the pointing and clicking I did to make the first map. Whereas with something like R one could write a script and use it to reproduce future maps. But perhaps there are some features in QGIS that I am unaware of that could help with reproduciblity.

Data for the map came from my existing Minamata Convention map on CARTO. I exported the shapefile and used it to create the layers in QGIS. My approach differed a bit from Alasdair’s because in my map not all the polygons are highlighed, only the countries that have ratified.

Incidentally, I was not able to create this animation in CARTO because it only allows animation for points, and I needed to show polygons (country borders).

After exporting 84 frames I used gifmaker.me to make the gif rather than the GIMP or Photoshop. Worked just fine.

Mercury Arcana

Here’s a little project I created to try out the free online graphic design package Canva. While it won’t replace a full-service tool like Illustrator, Canva makes it very easy to create attractive presentations, posters, and simple infographics. It’s definitely worth a try.

Has Your Country Ratified the Minamata Convention on Mercury?

This map shows the current status of ratifications of the Minamata Convention on Mercury. Although I update it frequently, check mercuryconvention.org for the most recent status. The map also shows countries engaged in Minamata initial assessment (MIA) and artisanal and small-scale  gold mining national action plan (NAP) projects funded by the Global Environment Facility (GEF), along with the implementing agencies. Use the “Visible layers” function on the map to toggle between ratification status, MIAs, and NAPs. The full screen button, located below the zoom controls, is also useful.

Data on ratification and GEF project status from the Interim Secretariat of the Minamata Convention and UNEP. Country boundaries from Natural Earth. Mapping done in CartoDB using Robinson projection.

Two Ways to Map Global Mercury Emissions

I’ve been playing with an interesting dataset recently, and it got me thinking about challenges in effectively visualizing geospatial data. Specifically, how do you best display a continuous variable whose values span several orders of magnitude?

The dataset I’m working with comes from the Arctic Monitoring and Assessment Program. It’s a estimate of global anthropogenic emissions of mercury per 0.5 x 0.5 degree grid square. One important reason why AMAP generated these data (and how they did it is an interesting problem and the topic for another post) was to help atmospheric transport modelers who need to know where on earth emissions are coming from. But the data also allow for a nice visualization of global sources of mercury pollution that goes beyond simple maps showing emissions by country.

I’ll present two options here, and I’d love feedback on what works best. I think there are also trade-off depending on what the purpose of the visualization is (presentation vs. exploration) and the scale. Both are made on CartoDB. You can zoom, scroll, and click on a point to see the data. Check out the full-screen option which I think is pretty cool.

The first is perhaps the more flashy one. It uses yellow circles whose size are proportional to mercury emissions. There is a multiply effect so areas of overlap appear orange-red.

This one is a more traditional chloropleth approach using an orange-red scale to represent the magnitude of emissions over each grid square.

Some technical notes:

The dataset contains around 45,000 grid squares (areas with no anthropogenic emissions, like oceans, are no data) with mercury emissions ranging from about 10^-5 to 12,000 kg. That’s around 8 orders of magnitude. Some quick exploration of the data revealed that almost all the mercury emissions came from less than 10 percent of the model area.

global hg dist

Cumulative sum of mercury emissions (normalized to 1) as a function of magnitude of emissions in each cell. Almost all emissions are from cells with greater than 10 kg emissions. Note log scale on x axis.

Most areas have very small emissions, but a few have very high emissions. The data are like this because the emissions estimates are made using both point sources, “area” sources like artisanal mining, and population as a proxy for some general emissions. In any case, to facilitate visualization I  removed the very-low-emissions-value grid squares. The remaining ~5000 squares comprise ~93% of total emissions. These data still have a pareto-like distribution ranging almost three orders of magnitude, but they are easier much easier to display on a map.

global hg dist tail

Cumulative sum of mercury emissions (normalized to 1) as a function of magnitude of emissions in each cell. Cells with < 50 kg Hg removed. Note log scale on x axis.

Note that the maps display mercury emissions per square km for each cell, not total mercury emissions. That is because the areas of the 0.5 x 0.5 grid cells vary with longitude. Those closest to the equator are larger, closer to the poles are smaller. So it makes for a more accurate display to normalize by the cell area.

An important factor in the visual appearance of continuous data like these is where to choose the breaks separating data points into different colors or sizes. This is especially difficult with pareto or power law distributions. CartoDB has several built in options for binning data. After playing around with them I choose head/tail breaks, which seems to work well on this type of distribution. CartoDB also allows you to easily change the breaks manually with cartoCSS. It was a challenge to find a binning and color/size scheme that portrayed the data in the most accurate way, while also maintaining a clear and striking appearance.

Color on the chloropleth comes from colorbrewer.

For more information on the development on the emissions model, see this paper.

Mercury in Chlor-Alkali Plants Mapped with CartoDB

The other day I learned that wordpress.com now supports embeds of CartoDB maps. This is pretty cool, and it inspired me to finish up a little project that I’ve been tinkering with for a while, in order to try out the new feature.

By the way, CartoDB is a web mapping tool that I think is one of the best interfaces available for creating interactive maps. You can make great looking maps quickly and easily, but there is also enough functionality to do more advanced stuff, like mess around with the CSS code.

This map shows estimates of how much mercury is on site at chlor-alkali plants per country. It distinguishes between countries that ban the export of mercury and those that don’t. This is important because chlor-alkali plants often contain hundreds of tons of mercury. When the facilities close the mercury can enter the commodity market where it can be used in artisanal gold mining.

The size of the bubbles reflects how many tons of mercury are estimated to be in chlor-alkali facilities in each country. Scroll, zoom, hover, or click for more details. The data are from the UNEP Global Mercury Partnership chlor-alkali inventory.

Technical CartoDB note: In order to distinguish (by bubble color) countries with and without export bans, I made two layers from the data table. However, because each set had a different range of values, the scale for the bubble size was different for each color. To fix this I manually changed the bubble size distribution cutoffs in the CSS tab. Is there an easier solution that I am missing?

Oh yeah, this is how you do the embed.

Updated Global Mercury Pollution Viz and Graphics

One of the first posts on this blog was about using Tableau to visualize data on global emissions of mercury.  I’ve gotten suggestions from a few people and given the graphic a bit of a face lift. Click on the image to see the interactive viz:

Dashboard_1 (3)

Click for interactive graphic

I also used the same dataset to make some static graphics using ggplot2 and the ggthemes package. I’d love any input on how to improve the the look and feel of both these and the Tableau viz. I’ve always found picking good colors very challenging, so thoughts on the palettes are especially welcome.

hg.emissions.bysec

The 8 industry sectors with the highest global mercury emissions. Data for 2010 from the 2013 UNEP Global Mercury Assessment.

hg.emissions.bycty_fewm

Countries with the highest mercury emissions. Data for 2010 from the 2013 UNEP Global Mercury Assessment.

Another Way to Look at Mercury in Seafood

In the previous post, I used Tableau Public to create a visualization of the Seafood Hg Database. That graphic showed the mean mercury content and number of samples by seafood category. But there are several other dimensions in the database, including the year of the study and the particular species of seafood sampled. I couldn’t resist playing around with the data a little more, this time using the lattice package in R.

The plot below shows the mean mercury concentration (y-axis) in studies of the 12 seafood categories with the highest median mercury concentration. The x axis shows the date of the study. I’ve also plotted a trend line for each panel. This is a nice way to visualize the data, but I wouldn’t read too much into this plot. For one thing, many of the seafood categories contain multiple species, some of which are higher than others in mercury. Also, this plot does not account for the geographical region where the fish were sampled.

fish.hg.latticeplot
We can tease a little more from the dataset by looking at the individual species within a seafood category. Here is a plot of the six tuna species with the greatest number of studies. The larger species, like bluefin, seem have higher mercury contents than the smaller ones, like skipjack. One curious feature of the dataset is also visible here: there were very few studies of mercury in seafood in the 1980s.
fish.hg.tunaplot

How Much Mercury is in Your Favorite Seafood?

I’ve written before about mercury emissions, mercury as a commodity, and mercury use in artisanal mining. But the reason we pay so much attention to mercury is because of its human health impacts, and these are primarily caused by eating contaminated seafood.

Different types of seafood have different amounts of mercury. Because mercury is bioaccumulative, organisms that are higher on the food chain tend to have greater mercury concentrations. Of course, the particular environment where the organism lives also plays a big part.

Scientists have been interested in the mercury content of seafood for decades. Recently, a group of researchers undertook the herculean task of aggregating data from almost 300 studies. The result is the Seafood Hg Database (and an accompanying paper). The database contains the mean mercury concentrations measured in each study for one or more of 62 seafood categories. Overall, the database represents over 62,000 individual measurements from around the world.

It’s a great dataset to play around with and experiment with visualizations. In the graphic below, I plot mercury concentrations for a subset of common seafood types. Each circle represents the mean concentration measured in one study, and the size of the circle is proportional to the number of samples in that study. I’ve overlaid box plots for each seafood category that show the median of all the means, as well as first and third quartiles (whiskers go to 1.5x the IQR).

I think this is much more instructive than simply plotting the grand mean (average of all the study averages) for each seafood category. For one thing, you lose a lot of information on how much mercury concentration varies within a category. Take tilefish, for example. This is one of the species that EPA and FDA advise pregnant women not to eat. But there are relatively few studies of tilefish, and the mean mercury concentrations they measured vary by an order of magnitude.

Click on the image below to bring up the full interactive Tableau Public visualization:

Hg in seafood

Click on the image to see full version

Satellite Image Time Lapse of Artisanal Mining in Peru

My last post was about gold and mercury prices, and how we might measure their relationship. We would expect a relationship between prices of these metals because mercury is used in artisanal and small scale gold mining (ASGM). We may or may not see a signal in mercury prices related to ASGM, but we most definitely see the effects of ASGM on the landscape on a massive scale. Using the Landsat Annual Timelapse tool in Google Earth Engine, I created this animation showing the explosive growth of ASGM and associated deforestation near Huaypetue in the Madre de Dios region of Peru. Click on the image below to view the animation.

asgm landsat anim

You can see that beginning in the late 1990s, large areas around rivers turn from green (rain forest), to brown (cleared areas for mining). The trend seems to accelerate in the last 10-15 years. You can explore the region as it appears today in Google Maps:

And because it’s fun to play with Google maps, here is a striking oblique image of the region.

Zooming in a bit closer, seen from a plane flown by the Carnegie Airborne Observatory, the impacts of mining come into even sharper view:

The scenes on the ground look every bit as desolate as you would expect from the satellite and airborne imagery:

Embed from Getty Images

Embed from Getty Images

If you are looking for more information on artisanal mining in Madre de Dios, this article in Nature is a good place to start. The Guardian has also been covering this region. This piece focuses on mercury use in mining and its toxic impacts.