Pies On A Map

Pie charts get a lot of hate. They are often associated with mass-market journalism that intends to obfuscate and trick the reader rather than to accurately convey information. The knock on them is that they make it difficult to compare proportions by not placing them side-by-side and by turning one-dimensional quantities into two-dimensional ones. However, there is one case in which I think pie charts have a place. On maps, if you want to associate a variety of numbers with a single point location, the conveniently circular form of the pie chart lends itself to being centered on the point of interest, more so than a histogram or stacked-bar chart. I wanted to make a map with pie charts at different points to show the land cover proportions of some of the sites in the National Ecological Observatory Network (NEON).

Here are a blank state map, the pies, and the two combined together:


Map, including a legend for the pies


The pies plotted individually with no formatting


Pies placed in their proper locations on the map!

Below, I present the R code that I used to make the map, using the ggplot2 , plyr, and grid packages.

# Pies On A Map
# Demonstration script
# By QDR

# Uses NLCD land cover data for different sites in the National Ecological Observatory Network.
# Each site consists of a number of different plots, and each plot has its own land cover classification.
# On a US map, plot a pie chart at the location of each site with the proportion of plots at that site within each land cover class.

# For this demo script, I've hard coded in the color scale, and included the data as a CSV linked from dropbox.

# Custom color scale (taken from the official NLCD legend)
nlcdcolors <- structure(c("#7F7F7F", "#FFB3CC", "#00B200", "#00FFFF", "#006600", "#E5CC99", "#00B2B2", "#FFFF00", "#B2B200", "#80FFCC"), .Names = c("unknown", "cultivatedCrops", "deciduousForest", "emergentHerbaceousWetlands", "evergreenForest", "grasslandHerbaceous", "mixedForest", "pastureHay", "shrubScrub", "woodyWetlands"))

# NLCD data for the NEON plots
nlcdtable_long <- read.csv(file='https://www.dropbox.com/s/x95p4dvoegfspax/demo_nlcdneon.csv?raw=1', row.names=NULL, stringsAsFactors=FALSE)


# Create a blank state map. The geom_tile() is included because it allows a legend for all the pie charts to be printed, although it does not
statemap <- ggplot(nlcdtable_long, aes(decimalLongitude,decimalLatitude,fill=nlcdClass)) +
geom_tile() +
borders('state', fill='beige') + coord_map() +
scale_x_continuous(limits=c(-125,-65), expand=c(0,0), name = 'Longitude') +
scale_y_continuous(limits=c(25, 50), expand=c(0,0), name = 'Latitude') +
scale_fill_manual(values = nlcdcolors, name = 'NLCD Classification')

# Create a list of ggplot objects. Each one is the pie chart for each site with all labels removed.
pies <- dlply(nlcdtable_long, .(siteID), function(z)
ggplot(z, aes(x=factor(1), y=prop_plots, fill=nlcdClass)) +
geom_bar(stat='identity', width=1) +
coord_polar(theta='y') +
scale_fill_manual(values = nlcdcolors) +

# Use the latitude and longitude maxima and minima from the map to calculate the coordinates of each site location on a scale of 0 to 1, within the map panel.
piecoords <- ddply(nlcdtable_long, .(siteID), function(x) with(x, data.frame(
siteID = siteID[1],
x = (decimalLongitude[1]+125)/60,
y = (decimalLatitude[1]-25)/25

# Print the state map.

# Use a function from the grid package to move into the viewport that contains the plot panel, so that we can plot the individual pies in their correct locations on the map.

# Here is the fun part: loop through the pies list. At each iteration, print the ggplot object at the correct location on the viewport. The y coordinate is shifted by half the height of the pie (set at 10% of the height of the map) so that the pie will be centered at the correct coordinate.
for (i in 1:length(pies)) print(pies[[i]], vp=dataViewport(xData=c(-125,-65), yData=c(25,50), clip='off',xscale = c(-125,-65), yscale=c(25,50), x=piecoords$x[i], y=piecoords$y[i]-.06, height=.12, width=.12))

Si quaeris peninsulam amœnam, circumspice

Switching gears to lighter fare . . . the title of this post is the delightfully unique and corny state motto of Michigan. In English, it reads “If you seek a pleasant peninsula, look about you.” I’ve been in East Lansing for about a month now, and so far things have been relatively pleasant. On my first week working as a postdoc in the forestry department, I helped my labmate do some sampling at a pond near the Kellogg Biological Station in southwestern Michigan. The land used to belong to the famed cereal magnate, who established a health resort nearby, coining the word “sanitarium” in the process. Despite a disturbingly high emphasis on enemas, the rich and famous of the day flocked there until the stock market crash put an end to the business.


The Kellogg Manor

It’s ironic that the Kellogg name is now associated with products like Frosted Flakes that you should probably steer clear of if you care about your health, digestive or otherwise. But Kellogg certainly knew how to build a nice pad for himself, as you can see in the photo I took of his manor. Now, the manor and surrounding land belong to Michigan State and are the site of the Kellogg Biological Station.

We spent a fun afternoon sampling the aquatic vegetation in a pond at a site a few miles down the road from the biological station. The research project involves interactions between damselflies and their prey (the blue insect in the photo below). We floated a PVC quadrat at different locations along a transect at the pond’s edge, estimated the relative abundance of different functional groups of aquatic plants, and collected them for biomass. It was a fun day of participating in fieldwork, though my current position will involve precious little getting out in the field. Mostly, I’m happy about that but spending a beautiful early June day outside in southern Michigan certainly makes you appreciate the “pleasant” side of fieldwork!

Thoughts on the Orlando massacre

This is a little late in coming (13 days after the event, which already seems to be slipping out of the public consciousness), and also my first try at writing up anything resembling an original opinion in blog post format, so I apologize for both those things.

I first heard about the Orlando massacre by word of mouth–I was attending a cousin’s wedding and cut off from news. After catching a couple of fragmentary details here and there, Mary and I decided to willfully ignore the news until the weekend was over. Once the celebratory mood had subsided, I sat and absorbed the awful news. The brutality of the massacre, and the predictable denouement that has followed so many of these events recently in the USA, was not unique, but for some reason felt rawer and more painful than ever.

The rush to dub the assailant a terrorist reminded me of a similar, though much less charged, debate that followed an event that took place when I was a freshman at UNC. To retell the story: One day, a friend and I were walking through a big lunchtime crowd in the “Pit,” a brick courtyard centrally located on campus where there is heavy pedestrian traffic during the day. After passing through the crowd and heading out toward the street, we heard screams from the crowd. At first, I mistook them for cheers that usually heralded the arrival of a UNC basketball player for a photo op. As it turned out, however, someone was driving an SUV through the crowd, flooring the accelerator and trying to hit as many people as he could. Most people leapt out of the way, but some unlucky ones were struck and bodies flew off the hood and into the air. I was 20 or 30 yards away and separated from the main crowd, but I caught a glimpse of the driver’s impassive face just before the car ran over the foot of an older professor who had not been able to escape in time, causing him to crumple to the ground in pain. The driver whipped the SUV around a corner on two wheels and drove off. During those decisive few seconds, I was transfixed with indecision–by the time I realized I should run, the danger was already over. I imagine I would react similarly in a more perilous situation, unfortunately.

Fortunately, no one was killed that day. Later, it turned out that the driver had been an Iranian-American man. Naturally, many people were quick to brand him a terrorist because of his professed anti-American views, despite him not belonging to any type of organization and likely suffering from mental illness. We were extremely lucky to have avoided anything worse–as we later learned, he had flirted with the idea of shooting into the crowd rather than trying to run people over. Imagining the same scene but substituting a semiautomatic rifle for the car makes the “guns don’t kill people” slogan ring hollow.

Learning about the horrible events in Orlando and remembering the incident in Chapel Hill makes me feel sad and worried about the future of humanity (in both senses of the word). I personally feel sometimes that pessimism and cynicism are holding me back from working harder to contribute meaningfully to society, and working to help create the world I want to live in. The events in Orlando, in some sense, have affirmed my pessimistic attitude: the kneejerk xenophobia, the stranglehold that capital and its lobbyists have on discourse (here specifically thinking of gun manufacturers), and of course the marginalization of LGBT people are all on display. “The best lack all conviction, while the worst/Are full of passionate intensity,” a line we first read in 10th-grade English class, comes to my mind. I hope that after the initial shock and sadness fade, this horrible tragedy will spur me (and others) not to indulge pessimism and negative attitudes but to make positive changes in society.

Evolution, linguistic determinism, and economics

As I mentioned in the post below, this was originally written in early 2014 shortly after the article in question came out. However I wanted to christen this blog with this old content.

A paper by an economist came out recently in the American Economic Review that made some seemingly outlandish claims and got a ton of press. The paper claimed that the way your native language conceptualizes the future tense influences your outlook on the future so strongly that it leaves a detectable signal in country-wide consumption data. Linguists, with tongues somewhat in cheek, have dubbed this “Whorfian economics” after the famous Sapir-Whorf hypothesis of the early twentieth century that language determines thought by limiting how categories are conceptualized in the mind. In my opinion, the claims made in the paper are not supported by valid evidence, because the models do not account for relatedness among languages and therefore overestimate the variation explained by future tense structure. Here’s why:

Some languages are obligated to mark the future tense with an inflection or particle (for example, English “I will go shopping tomorrow,” Italian “Domani faro’ le spese”). In contrast other languages either have no explicit future tense marker (Mandarin for “I will go shopping tomorrow”) or often simply express future events in the present tense (German “Morgen gehe ich einkaufen”). Languages like English and Italian are classified by Chen as “strong-future” languages, while languages like Mandarin and German are “weak-future” languages. According to Chen’s hypothesis, the “strong-future” distinction between present and future causes speakers to conceptualize the future as more distinct from the present — less tangible and less real. Therefore, they supposedly find concerns about the future less urgent and are less likely to save money. However, the correlation Chen found among future tense type and saving rate was largely driven by a single clade: the Germanic languages. They are all classified by Chen as weak-future, except for English which subsequently evolved an obligatory future marker — the verb-turned-grammatical particle “will.” Additionally, they are spoken in rich, financially conservative nations. Their shared recent common ancestor (about 2500 years ago) and contiguous geographical distribution confound any relationship between tense and saving rate.
Above is a phylogeny I made of the languages in Chen’s dataset, with the saving rate shown by the length of the colored bar (color indicates tense type).

First step the hardest?

Hi everyone! I am writing this because I have been waffling about the idea of writing a blog for a while. I decided that if I put something, anything, on here, it will make it tangible and easier to come back in the future and add more rather than being paralyzed over a blank slate. I am hoping to mainly write about things at least somewhat related to biology/nature/scientific inquiry, but may stray to other topics. I paraphrased Stephen Jay Gould in the tagline. His original quote applied to evolutionary biologists but I think it could be broadened to all scientists: “All [evolutionary biologists/ecologists/scientists] know that variation itself is nature’s only irreducible essence… I had to place myself amidst the variation.” We shall see if my writing lives up to such pithy eloquence. As for the first blog post, I will put something up that I actually wrote 2 or 3 years ago but had hosted on a google site that was rarely if ever visited. I think it embodies the spirit of this blog and of my worldview, tying together as it does biology, language, statistical inference, and natural variation.