Learning R Versus d3.js for Visualization

Posted to Guides  |  Tags: ,  |  Nathan Yau

For those who work with R and d3.js, the differences between the two are obvious. But for those who are brand new to this world, the names might as well be gibberish. This quick primer is for the latter group.

So R or d3.js for visualization? People ask me this fairly often, because I usually mention the two at the end of of my interactives.

Here’s the quick answer:

If you want to make non-interactive, static graphics or just need image files at the end of the day, R is a good place to start. If you want to make interactive or animated graphics that work in a browser, then go with d3.js.

Longer Answer

With that said, the answer varies depending on your programming experience, what data you have, and specifically what you’re trying to make.

R is a statistical computing language that was developed by statisticians to analyze data. More recently, R has expanded its use cases as data spreads into other application areas. There are also a lot of R packages that let you do more with a lot less code than if you were to start from scratch.

Visualization is only a part of what R is typically used for. You can manipulate data, aggregate, summarize, analyze, and quickly comb through your dataset with a bunch of quickfire charts.

Data-Driven Documents, or d3.js, on the other hand is a “JavaScript library for manipulating documents based on data.” So if you learn how to use d3.js, you actually learn JavaScript. If you’re brand new to programming, this can prove to be an uphill battle at first. But as with anything, once you get it and understand what’s going on, the results feel like they were worth the initial effort.

R is more kind to beginner programmers, with a lot of one-liners, but you can’t quite do as much. There are packages that let you export graphics to JavaScript, but the results still feel a bit canned and not as flexible for my own taste. Then again, you get an interactive graphic without ever having to learn JavaScript.

I’m more tool-agnostic in my approach. It’s whatever gets me to where I want to go the fastest. I use R for analysis and quick charts to see what a dataset looks like. Then, if I want make the results interactive or animated, I shift to d3.js with the results I found in R in mind.

I guess it comes back to the original question of what you ultimately want out of your visualization. For static graphics, R is a good way to get quick results. For interactive and web-native graphics, check out d3.js.

If you have the time, it’s great to have both in your toolbox.

Favorites

Think Like a Statistician – Without the Math

I call myself a statistician, because, well, I’m a statistics graduate student. However, the most important things I’ve learned are less formal, but have proven extremely useful when working/playing with data.

The Best Data Visualization Projects of 2011

I almost didn’t make a best-of list this year, but as I clicked through the year’s post, it was hard …

19 Maps That Will Blow Your Mind and Change the Way You See the World. Top All-time. You Won’t Believe Your Eyes. Watch.

Many lists of maps promise to change the way you see the world, but this one actually does.

Watching the growth of Walmart – now with 100% more Sam’s Club

The ever so popular Walmart growth map gets an update, and yes, it still looks like a wildfire. Sam’s Club follows soon after, although not nearly as vigorously.