Learning R Versus d3.js for Visualization

October 7, 2016

Topic

Guides  /  ,

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.