Pop Viz: 4 Years of Reddit and Using the JS API

April 14, 2014
Happy Cakeday to ME!

Last Saturday was my 4th “Cakeday” on everyone’s favorite time waster, Reddit! To celebrate another year of distraction, I wanted to update my Cakeday Karma Count dashboard from last year. I’ve learned a lot of tricks since then, so this new and improved dashboard has a couple of upgrades:

  1. Getting the data was way easier.
    Last year (and I shudder thinking about this) all my data was hand inputted into a spreadsheet. Now that I’ve learned a little more about the beautiful world of web scraping via import.io, I was able to get all this data in just a couple minutes!
  2. I learned how to use Imgur URL Parameters.
    This is actually a fairly new discovery for me. I found out about it when one of the students in my DDJ class was playing with Reddit data and wanted an easy way to resize all the Imgur links. Just adding an “m” to the end of the ID made it easy for me to switch between the three images that change in the URL object without having to manually resize all of them.
  3. I learned how to use Tableau’s Javascript API to have URL actions work both on a Web page object on the dashboard and in a new tab!
    This is by far the best discovery. Mad props to JSAPI genius Michael Kovner for helping me with this solution. When I made the dashboard last year, I wanted people to be able to open up the links to my posts, but it would load where the image changed instead of in a new window. Turns out just a few lines of javascript can fix it! More about the solution after the viz!




If you click on a bubble, you’ll notice the picture change. If you click on the box/arrow symbol thingy in the table, it’ll open up the link to that post in a new window (pop-up blockers may mess with this). Try it out!



So here’s how the double URL action works.

I created a normal URL action that changes the picture while editing the dashboard. The action that controls opening a post in a new tab is done completely in the Javascript API. All I had to do before publishing is make sure that the sheet that I wanted to control this action had the proper URL dimension I wanted to use.

After I published the dashboard, I created a javascript file called reddit.js that looked like this:

window.onload = function() {

var sheetDiv = document.getElementById("visualization");
var sheetURL = "http://public.tableausoftware.com/views/reddit/4years";
var sheetOptions = {
hideTabs: true,
hideToolbar: true,
width: "900px",
height: "1200px",
onFirstInteractive: function() {
}
};
viz = new tableauSoftware.Viz(sheetDiv, sheetURL, sheetOptions);

viz.addEventListener('marksselection', function(event) {
if(event.getWorksheet().getName() === "Post table") {
event.getMarksAsync().then(function(marks) {
if(marks.length === 0) {
return;
}
link = marks[0].getPairs().get('Link').value;
window.open(link, '_blank');
});
}
});
};

Let’s dissect what some of these parts are. The first section there is really just setting up that this script is generating a viz and we are going to do stuff to it. If you wanted to re-purpose this code for your own viz, you would replace the “sheetURL” with your viz and the width and height with what your dashboard is sized to. The second part is the event that controls the URL action. This function tells the viz to open a URL dimension named “Link” from a sheet called “Post Table” in a new window. If you wanted to use this on your own dashboard it would look like this:

viz.addEventListener('marksselection', function(event) {
if(event.getWorksheet().getName() === "SHEET NAME HERE") {
event.getMarksAsync().then(function(marks) {
if(marks.length === 0) {
return;
}
link = marks[0].getPairs().get('URL DIMENSION NAME HERE').value;
window.open(link, '_blank');
});

Once you have the code written, you’ll need to save the javascript file somewhere on your site. Then, when you are embedding, you’ll reference the Javascript API and your javascript file and call up the visualization like this:

(script src="http://public.tableausoftware.com/javascripts/api/tableau_v8.debug.js")(/script)
(script type="text/javascript" src="reddit.js")(/script)
(div id="visualization")(/div)

Note: all the parentheses are supposed to be triangle brackets… I can’t put them in that way or WordPress will think I’m trying to actually use them. :P

That’s pretty much it! Thanks again to Michael Kovner for the awesome script and to my pal Josh Buchacher who helped me figure out how to embed this properly on my blog!

Data Feed: Prices for Vices Around the World

April 1, 2014

Saw an interesting little article here.

All the charts have a “Get the data” link under them. If I were you, I’d combine all this nice juicy data into one dataset and see what the correlations between different vices are.

DRUGS

Data Feed: U.S. States’ Ability to Survive a Zombie Apocalypse

March 26, 2014

So…one of my facebook friends posted this dataset:

ZOMBIES!(click to see their analysis)

So yeah. Pretty self-explanatory. And also pretty awesome. I know there’s plenty of Zombie loving people out there that’ll probably want to do something with this. I leave you with one of my favorite songs of all time, which also happens to be very relevant.

Data Feed: MCN Performance Index

March 25, 2014

My friend Steven shared this dataset with me on motorcycle performance stats. I don’t really know anything about motorcycles, so I couldn’t really figure out what to do with it, but I’m sure one of you lovely people out there can make something cool. So have at it! The data is available here!

Hardcore biker

Pop Viz: What music matters most to KEXP?

March 24, 2014

KEXP is a local public radio station here in Seattle. It’s an awesome station and they play lots of indie and lesser known bands. They stream online, so everyone can enjoy their awesomeness. They also keep a live-updated playlist that shows every song they ever played since 2001. Pretty incredible and kind of a data-slash-music-nerd’s dream. I used import.io to scrape everything from 2013. I’m going to work on getting the other years in there, too.

I had all kinds of grand ideas on what kinds of things I would do with this data. I made a lot of crazy looking charts. But when it came down to it, the simplest charts told the best stories. So I scaled back. What ended up being what I think is the most interesting dashboard with this data is pretty plain. It’s simply how many plays a dj played an artist/album/song.

Learn About Tableau

If you want a little more depth than that, I made another dashboard that will let you see which songs by a particular artist each DJ plays and when they play it:

Learn About Tableau

I was playing with some of the time-based data as well. When I did a plot of Week vs Song Plays, it’s pretty obvious to see when KEXP is doing a pledge drive; number of songs played drops over 15% each time. I also looked at the weekly schedule by making a heat map of days of the week versus hours in the day. You can see blocks where they play less music: like Saturday and Sunday mornings when a local news talk show plays instead. The heat map under that shows the number one artist by plays for each hour of each day. Apparently 12am on Thursday is a really good time to hear some David Bowie.

Learn About Tableau

Enjoy exploring these dashboards and learning where my hipster taste comes from! And if you love music as much as I do, be cool like me and help support KEXP!

That's exactly what I look like rocking out to KEXP on the bus.

Quick tip: Sort by combined fields

March 19, 2014

This is a pretty simple tip, but it’s something I see new users struggle with all the time. Sometimes, sorting is a pain. Actually, most times sorting is a pain, especially when you are dealing with multiple dimensions.

JUST PUT THE BIGGEST ONE ON TOP!! GAHHHHH!

For example, I was working with some music data and I wanted to show a simple bar chart of the top songs and which album they were from. When I first dragged in the pills, it came out looking like this:

WHY?!

So… we have some problems. Some songs are on more than one album (e.g. a studio album and a live album). Also, there are a bunch of different songs with the same name (e.g. “Home”). So sorting this way won’t work. Doing it by album is even worse because many albums have multiple songs played from them:

WHYYYY?

So… what can we do? We have multiple songs on a album and multiple albums featuring a song. How do we get a unique dimension to sort on so they aren’t grouped? We combine the fields! It’s a simple process, just select the dimensions you want to combine, right click and select “Combine”

Easy peasy!

Now we can add this new combined field to the rows shelf and everything is magical. We can even hide the header so that the end viewer is none the wiser.

YAYYYYYYYY!

Hopefully this will help you sort through frustrations with sorting!

Jobs and Earnings in the U.S. 2001-2013

March 18, 2014

A couple weeks ago, I helped create a couple of dashboards in collaboration with Careerbuilder and EMSI. You can view them here. We came up with some cool stuff, but I was really sad that they weren’t interested in using what ended up being my favorite graph I made. But, it didn’t really fit in with the story they were making. Luckily, they didn’t mind if I reposted it here, so that’s what I’m doing.

The viz is showing how the number of jobs and average earnings per job for a number of industries and sub-industries have changed. I created it using a basic scatter plot with year on pages. By allowing the pages shelf to “Show history” I created dotted line trails to show the path that each industry took over the 12 years of data. I thought this was a really interesting view since you can almost see the “shape” that an industry took during this tumultuous time in our economic history. As I mentioned, the data in courtesy of EMSI. All the monetary amounts are adjusted to 2013 dollars.

Check it out:

Learn About Tableau

Here’s a few of the findings I found interesting:

Since pages don’t have the play controls when published to Tableau Public, you are missing out on watching the fun animation. So, I created a little gif action for you to get hypnotized by:

 

industryviz

Data Feed: All the Sports!

In case you missed it, Ben Jones created this awesome viz of where to viz sports data!

Learn About Tableau

Sports Viz contest entries are due this Friday, so get some sports data and get vizzing!

GOOOOAAAAAAALLLLLLLLLLLLLLLLLL

Pop Viz: History of Drum Corps

March 5, 2014

If you haven’t already seen the news, we’ve announced the first two themes of this year’s Iron Viz feeder contests. The first contest, which starts next Monday is going to have a Sports theme. This was problematic for me because I don’t know ANYTHING about sports. Aside from one really poor season of track and field in 7th grade, I’ve never really played sports. I was always more of a band/drama/dance kind of person.

This is why I got a D in Team Sports.

But I was on a team. I was on a team that practiced harder and longer than most sports teams at my school did. I was on a team that was driven and consumed by a desire to be champions. I was on a team that was not only about physical coordination, but also teamwork, synchronicity, musicality, and artistry. I did marching band.

Marching band taught me about teamwork and perseverance. It helped an awkward, skinny teenage nerd like myself feel coordinated and graceful. And the year that I was drum major (that’s the person who conducts the band), my arms rivaled Michelle Obama’s. Marching band was also how I first learned the rules of football and basketball; when I was drum major, I had to know when to queue up certain songs, so I had to learn to follow the games.

Best outfit ever

Competitive high school band is one thing, but there is actually a “professional” side to this sport, Drum Corps International. Every summer, groups of incredibly talented high school and college students battle it out in competitions all over the United States as a part of DCI. If you are still skeptical about the legitimacy of marching band as a sport, consider that they actually played DCI championships on ESPN. So, yeah, it’s totally a sport. And it’s awesome. And I made a dashboard of it that includes videos so that you can fully see how awesome it is.

You can click on the logo of a corps to view their score history, some facts about them and see an example of one of their performances. On the bottom half of the viz, you can click a corps on the bottom left bar chart to filter the bottom right to just their winning shows. And you can click on the bars in the Winning Shows chart to view those in the youtube player. I got all the data from Corpsreps.com, which I scraped using, you guessed it, import.io. Here it is:

Learn About Tableau

As you can see, the Blue Devils pretty much dominate everything, and for good reason. They are incredible. Former Blue Devils coached and wrote the show for our high school marching band one year and we won our division in the state championships. This is going to look pretty mediocre if you’ve watched some of the amazing performances in my dashboard above, but trust me, it was super cool. I was marching tenor saxophone in this performance and it was the most fun I had in all of high school.

I might post some tutorial-like stuff about this dashboard later. If there’s anything you are curious about with how I got the data or made the viz, feel free to leave me a comment or drop me a line on Twitter. I will definitely be following this up with a viz about another nerdy, sport-ish thing I participated in, Winterguard, aka “The Sport of the Arts.” Because dancing around with swords is DEFINITELY a sport.

I'm not sure how I never poked my eye out.

Data Feed: Top 1000 Reddit posts from top 2500 Subreddits

March 4, 2014

Here’s a dataset I’ve always wanted to play with but never had time to fully explore: Reddit Top 2.5 Million posts.

An awesome Redditor compiled this list together. I’ve always wanted to use it to figure out when the best time/day to post for maximum karma is. Give it a go and reap the orange benefits.

NEED DAT UPVOTE

← Previous Page