Viewers: in countries Watching now:
Start communicating ideas and diagramming data in a more interactive way. In this course, author Barton Poulson shows how to read, map, and illustrate data with Processing, an open-source drawing and development environment. On top of a solid introduction to Processing itself, this course investigates methods for obtaining and preparing data, designing for data visualization, and building an interactive experience out of a design. When your visualization is complete, explore the options for sharing your work, whether uploading it to specialized websites, embedding the visualizations in your own web pages, or even creating a desktop or Android app for your work.
- If you have a variable that changes over time, one very good way of looking at this is with what's sometimes called a time plot or an area chart or just a line chart, and in this movie, I'm going to show you how to produce a variation on the line chart that does a really good job of drawing changes and interest and in particular, Google search term over time. Now, in this one, I've got my palette there up at the top. Then, I call two fonts because I'm gonna be using one for the titles and one for the labels.
Then I'm calling up some data about art. What I did is I went to Google Correlate and I got the search trends over time for the French cubist painter, Georges Braque. That's going to be the data that we're gonna use. In the Table class, I'm creating an object artData. After that, I have a rowCount, and then I had to do an interesting thing because I have two forms of interaction here. I need to create a secondary variable that can also record the mouse position, but I started just slightly off of the visualization.
After that, I have the setup block. I have a window that's 600 by 200. Then, I take my artData objects that I created earlier in the Table class and then I load the braque.tsv file into it. That's a tab-separated values file and the easiest way to get those is by opening a file in Excel and saving it as a tab-separated values text file and then manually changing the extension after you saved it. Then I have a Table function where I get the row count, then I print the row count at the bottom as a way of double-checking that I'm reading things correctly.
Then I load two fonts; a bold, 18 point Gill Sans for the titles and a regular 12 point Gill Sans for some of the labels. And again, I created these with Processing's font tool. If you go up to Tools, we have Create Font. And as I mentioned before, the fonts available on our computer and the fonts available on your computer might be slightly different. If you don't have Gill Sans, don't worry, you can either comment out those lines completely or you can replace them with fonts that you create using the ones available on your computer.
Either way would work fine. Then, last thing into the setup block is I turn on the anti-aliasing with the smooth function. Going down to draw, one of the interesting things I do here is I turn off the cursor completely. You can have a choice of the arrow cursor, a hand cursor, a crosshair cursor, the text I-beam cursor, the Spinning Beach Ball of Death wait cursor, and you also have the option of turning it off completely. Actually, you can also load an image file as a cursor, but I decided for this one to get rid of it and I'll explain that, when you see it'll make sense.
Then I put the background color in. I call up the text font and then I put in some color information for the stroke and the feel, and I'm going to center the title across the top. It says, "Google Searches for Georges Braque." Then I'm going to start aligning some other information for the labels. Let me come down here. Then I have a for loop that goes through and reads the data file. So I tell it first that I want to go through row by row starting at the very tippy top because my TSV file doesn't have any header information. It's just starts with the data.
That's one of the reasons that I save an additional version of the file with either CSV or XLS file that has the headers for reference purposes. But it says to go through and to first read the dates. I have date information with the month and year because when I went to Google Correlate, you can download either information in a week by week or month by month. The month by month is a little cleaner for this one, so that's what I chose. So that comes in in strings and then I used the getString method then I go to pull out the popularity data and that's the actual Google search relative interest in it.
Below that, as I showed in the last movie on scatterplots, I create x and y variables using Processing's map function. What that does is it's able to take the two variables about the row numbers and about popularity numbers and it's able to convert them from their existing scale, for instance for the rows, it goes from 0 to 104, and I'm able to change that to a 30 to 575 scale, to spread things out evenly. Similarly, with the popularity, it's able to take a -2 to +4 scale and it's able to spread it out from 150 to 20.
It's actually changing the direction because I want higher numbers to be higher up on the window whereas conventional computer numbering starts with lower numbers at the top and gets higher as it goes down. So this flips it around for me automatically. Then, what I have is a couple of lines that are currently commented out that I use just to check that this is working correctly. For instance, this line right here will print out 104 lines of the popularity data formatted with one digit on the right and three decimals places, and with a + or - in front of it.
Then, I've gone off to the right, it'll do a semi-colon, then it will do the converted version of the popularity where it's mapped on to the 150 to 20 scale. And so, that's just something I did to check that it was working. I also turned on noLoop 'cause I didn't want it to just keep repeating and repeating in the console, but both of those are commented out. Then, I used something called slicing for the interaction. What that does is it lets me move the cursor from left to right behind the data and I've got it set up to bring in a line and when the line gets close to one of the data values, it pops in some information about that one.
In a later movie where I talk about forms of interaction, I am gonna talk about slicing a little bit more. But, you'll see how it works. Mostly, I'm saying, only do it when we're in the data window and I want you to draw a line of a certain height, and then if it's within two pixels of a data point, then I want to fill in this information that kinda floats like a flag at the top of the line. Beneath that, I draw the lines and the dots. What I'm doing is, I'm actually drawing dots at each data point as they go across, and then I'm drawing vertical lines from the bottom up.
So this is somewhere in between sort of like a bar chart and then an area chart, but I think it makes it clear and easy to read. Also, because it I have this stuff set in, I don't need a line across the bottom. Then I have something that reads the dates. Then, what it's gonna do is it's going to put in the January. It's starting on a January 'cause the data sets starts on January. Then it skips to every 12th row, so it lets me know when the first of the year starts. Right down here, that's where it places the dates.
I have to recreate the variables here, but I do them for only every 12th case. Then what this does is this changes the way that the lines are drawn for each January. It's the same color and everything, but it's a thicker line and also, it puts a square cap on it. I don't draw the ellipses anymore. And so, it makes it a way of telling where the year starts and stops. Then finally, below that, I have two blocks that are used for interaction. The first one is about keyPressed and it actually makes it so that I can manipulate my little interaction thing with the left and right arrow keys on the keyboard.
The other one is a function we haven't seen before. It's mouseMoved and that says, this one only kicks in if the mouse is not clicked and it starts moving. There's other ways you could have done this, but this is a shortcut one. And, between the two of these, you see they're both affect the variable mx, that stands for mouseX and they both affect the same way of gliding through the data to get the values. With that, I'll scroll back up to the top and I'll click Run.
There's my data set; Google Searches for Georges Braques and you see it started January of 2004 and it goes through July or August of 2012. And I've got a thicker red line for every January so it's easy to tell where each year starts. There's a couple of things you can see here. The most important one is you see that people search for Georges Braque when school is in session. The summer months are a huge dip every single year. Also, for reasons that are not clear, it looks like George Braque's general popularity is going down over time, at least slightly.
And we also have a few big spikes. For instance, in 2007, there's a big spike in interest and there's a couple of others. But now, let me show you how we can interact with this. I'm gonna bring the mouse over. You see I've got the mouse here on the side, but as soon as it hits where the bars are, the mouse will disappear. Now, I just have a line coming through with the information for each month, as it matches up to that line. So, for December of '05, the interest in Georges Braque was at .559, so that's slightly above average.
Whereas during the summer, August of '06, it's a standard deviation below average. Then here we got this spike and we got another spike over here. I don't really know what to make of those. I also want you to see that right now, I'm driving with the mouse. But if I let go of the mouse and just hit the left key on the arrow on the keypad, now I'm driving it with the keyboard and there's the right arrow, and I can stop and I can start moving the mouse. It picks up exactly where it left off. That's a really smooth form of interaction especially 'cause it lets them go from one to the other.
It also works really well to have the cursor just be completely absent so that people can see just the data and what needs to be in there. Anyhow, this is one way to create a form of line plot or time plot as a way of showing the prevalence of a single quantitative variable as it changes over time.
There are currently no FAQs about Interactive Data Visualization with Processing.
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.