Winston Chang’s R Graphics Cookbook (2013)

Chang_RGC_cov.pngIf you’re ever fumbling around with data in R, you’re probably familiar with the built-in, unattractive graphics. ggplot2’s been increasingly recognized as a necessity for getting the most out of your imagery. It offers nearly complete control over your graphics output, building them layer by layer.

I spent a solid year learning and exploring R as a graduate student before I cracked open Winston Chang’s R Graphics Cookbook and started learning ggplot2’s little oddities. ggplot2 is itself almost like another language within R, but it’s thankfully a very simple language — far more simple and far more flexible, I feel, than the built-in graphics options.

Since you’ll be printing your graphics step by step — your boundaries before your lines; your lines separately from points; etc. — it’s easy to keep track of where every impact on the output image is occurring, allowing you to easily tweak the code and get immediate results. E.g., if annotations are not lining up where you want, or font size needs to be reduced.

From my research. summaries of superposed epoch analyses across four separate sample sites, showing trees impacted by the defoliating western spruce budworm. Y-scale shows number of sites (1-4) reporting positive or negative PDSI anomalies using either reconstructed or historical datasets. Shaded regions show significance to either 90% or 95% depending on shading.

Chang’s cookbook is separated by what feature you need to either edit or create, making it easy to jump to what the reader needs. Full sections are devoted to bar graphs, line graphs, scatter plots, data distribution graphics, customizing annotations, axes, legends, color options, and cetera. Nearly 400 pages of text and images showing different ways of customizing and displaying every piece of your graphics. It’s not a book you read cover to cover — just the resource that ‘cookbook’ implies, meeting the reader’s specific needs.

If you want to just jump into the code and see what you can do with your own data, there’s no better place to start. Almost no time is devoted to unnecessary exercises or teaching you the fundamentals of the R programming language. Exploring the far reaches of the Internet is a free alternative that’s likely just as helpful, but Chang’s book serves as a great reference, and contains almost everything you need all in one.

Results of modified Ripley’s K-function, showing the degrees of insect outbreak synchrony between 4 sample sites. Shaded region represents bounds of significance (95%), with positive showing synchrony, and negative asynchrony. E.g., moderate outbreaks show significant co-occurrence of up to 11 years.

Please see my thesis research page for further examples of graphics built using ggplot2 and Chang’s cookbook.


Leave a Reply

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

You are commenting using your 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