Unconstant Conjunction latest posts

Don't Forget to Reproject Spatial Data when Exporting to GeoJSON

In the process of working on a recent choropeth piece for work, I discovered that it’s easy to stumble when moving spatial data out of R and onto the web. It’s a poorly-documented reality that many web-based mapping libraries (including both D3 and Leaflet) expect GeoJSON data to be in EPSG:4326, and it is by no means a given that that your spatial data will start off in this projection.

If you’re like me and do your spatial data pre-processing in R before exporting to GeoJSON, you may have to re-project your data before these libraries will handle them properly. Thankfully, this is fairly easy to do with the modern spatial packages.

Continue Reading →

An Update to the Choropleth Post

A few years ago I published a post outlining how to make nice-looking choropleth maps in R, and this piece still draws a reasonable share of my hits each month. Unfortunately, some of the techniques I used at the time are now quite out of date, and I was starting to feel bad for anyone taking my advice.

As of today the post has received a makeover, and takes a more modern approach. For any returning readers, the changes are explained in a series of HTML <ins> tags — which I have only recently discovered.

Continue Reading →

Custom Hexbin Functions with ggplot

Recently, I wanted to create a map similar to James Cheshire’s crime map of London, which shows the most common crimes commited in a rectangular grid of points laid over London. Instead of using a rectangular grid, I wanted to use hexbins, but it turns out that ggplot needs a bit of prodding to do anything other than simply count the number of observations in each bin.

At the time I couldn’t find a good tutorial on writing custom hexbin functions, so this post is a reasonably thorough explanation of what I’ve made work.

Continue Reading →

Not All Population Maps Are Boring

As the venerable xkcd comic points out, unadjusted geographic data often ends up looking like a population map. Normally, this makes it kind of boring, since it doesn’t tell you anything new.

Except, of course, when a visualizing the population is exactly what you had in mind. I discovered recently that the Australian government keeps track of every public toilet in the country, for example — and what better way is there to learn about Australian geography than through such an important public utility?

Australia, In Public Toilets

As usual, the remainder of this post is a technical discussion of how I created the graphic above. It was a neat opportunity to make use of hexbinning, and I’m quite fond of the end result. I haven’t yet figured out a way to add a “shadow” made of hexagons to indicate the overall shape of Australia, though I would like to. The fully reproducible code can be found in my visualization repository on Github.

Continue Reading →

Visualizing Health Expenditure using Spie Charts (and R)

Continuing with the theme of my last post, I wanted to put an interesting visualization together using some publically available data. The result is the following (somewhat surprising) graphic:


One of the looming issues in Canadian public policy is how to address the fact that our population is ageing, and that this will mean a larger burden on many of the social services that are more heavily consumed by those who are older. But just how uneven is the consumption of health services? The above should give you some idea of why this is viewed as a looming problem.

The remainder of this post is a technical discussion of how I created the visualization. I’m not quite satisfied with the overall approach (I think it takes quite a while before you can really read the graphic), but it does serve as a good technical demonstration of what can be accomplished in R.

Continue Reading →