Guides  /  ,

Learning R Versus d3.js for Visualization

Oct 7, 2016

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.


10 Best Data Visualization Projects of 2017

It was a rough year, which brought about a lot of good work. Here are my favorite data visualization projects of the year.

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.

Who is Older and Younger than You

Here’s a chart to show you how long you have until you start to feel your age.

Where Bars Outnumber Grocery Stores

A closer look at the age old question of where there are more bars than grocery stores, and vice versa.