How I Learned to Stop Worrying and Love the Alpha Channel

This is a short post about graphs with lots of data.  If you’re going to make a scatter plot, and there are lots of overlapping points use the alpha channel.  The alpha channel allows you to add the appearance of transparency to your plotting objects in R, meaning plots with multiple overlapping objects are resolved a little bit better.

It is really easy and it allows you to provide more information than just using a black dot.

plot(x, y, pch=19, col=rgb(0.1, 0.1, 0.1, 0.1))

That’s all there is to it.  It makes a plot like this:

A plot showing how crummy opaque plots are
Figure 1. Annual temperature and summer precipitation for a number of sites in eastern North America. The lack of transparency results in a loss of information about data density when density is very high.

Look like this:

Summer precip and annual temperature using the alpha channel
Figure 2. With the addition of the alpha channel it is possible to see that there are regions with much higher densities than others, above and beyond the ‘blob’ structure. It also makes possible artifacts from the derivation of the climate data visible.

Notice how much more information that added.  The first plot presents the assumption that there is uniform climate density in the heavily shaded region, but the second plot shows that there is spatial structure even in regions that have dense coverage of the climate space.  Some of the ‘climate threads’ are also visible.  I’m not really sure what they are, but I assume they’re artifacts of the interpolation process that derives the point based estimates of climate from regional weather stations.

Incidentally, I’ve started to use Hadley Wickham‘s plyr library.  Two things that make it great, (1) the ability to have a text progress bar going while you’re running a slow aaply function, (2) the fact that aaply on a sort doesn’t rotate your matrix.  I mean, what the heck apply?!  Of course, if you had read the help page for apply you’d know why, but nevertheless it always catches me by surprise.

Music for today:  Ian and Sylvia Tyson – Early Morning Rain I was really looking for the song ‘Wild Windy Weather’ which I think is really great, Ian Tyson’s got this vocal melody that plays counter to a really solid bass line, but this is pretty good too.  I’ve got a soft spot for Ian and Sylvia.

Published by

downwithtime

Assistant scientist in the Department of Geography at the University of Wisconsin, Madison. Studying paleoecology and the challenges of large data synthesis.

6 thoughts on “How I Learned to Stop Worrying and Love the Alpha Channel”

      1. The code is right in the post, just below the fold. The alpha channel is invoked when you call the ‘col’ argument in your plot. If you use ‘rgb’ to define the color you can add an alpha argument along with red, green and blue. The alpha sets the percent transparency. It’s not something you have to set prior to plotting.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s