Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
If you have a variable that changes over time, one very good way of looking at this is what's sometimes called a time plot or an area chart or just a line chart. And in this movie, I am going to show you how to produce a variation on the line chart that does a really good job of joining changes and interest and a particular Google search term over time. Now in this one, I've got my palette there at the top, and then I called two fonts because I'm going to 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, who is known for his Nude Descending a Staircase. So that's going to be the data that we are going to use. In the Table class I'm creating an object art data. After that I have a row count. Snd then I have 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 start it just slightly off of the visualization.
After that, I have the setup block, I have a Window that's 600 x 200, and then I take my art data objects that I created earlier in the Table class and then I load the braque.tsv file into it. That's a tab-separated value file, and the easiest way to get there is by opening a file in Excel and saving it as a tab-separated value text file and then manually changing the extension after you've saved it. Then I have a Table function, where I get the row count.
Then I print the row count at the bottom. It's a way of double-checking that I'm reading things correctly. Then I load two fonts, a Bold 18 pt GillSans for the titles and a regular 12 point GillSans 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 GillSans, 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.
And then the last thing in the setup block is I turn on the anti-aliasing with the smooth function. I'm 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 crosshairs cursor, the text I-beam cursor, the spinning-beachball-of- death weight 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 decide for this one to get rid of it, and I'll explain that. When you see it, 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 stroke and the fill. 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 tippy top, because my tsv file doesn't have any header information. It just starts with the data.
That's one of the reasons that I save an additional version of the file-- it's 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 on a week by week or month by month. The month by month will look cleaner for this one, so that's what I choose. So that comes in as strings, and then I use the get string 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 scatter plots, I create x and y variables using Processing's map function. And what that does is it's able to take the two variables about the row numbers and about the 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 is changing the direction, because I want higher numbers to be higher up on the window, whereas conventional computer numbering starts with low numbers of 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. So for instance, this line right here will print out 104 lines of the popularity data formatted with one digit on the right and three decimal places and with a plus or minus in front of it.
And then I've got off to the right, it'll do a semicolon. Then it will do the converted version of the popularity, where it's mapped onto the 150 to 20 scale. And so that's just something I did to check that it was working. I also turned on no loop because 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, and what that does is it let's 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.
Now, in a later movie where I talk about forms of interaction, I am going to talk about the slicing a little bit more, but you'll see how it works. Mostly, I am 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 kind of floats like a flag at the top of line. Beneath that I draw the lines and the dots. What I'm doing is I'm actually drawing the dots at each data point as they go across and then I am in drawing vertical lines from the bottom up.
So this is somewhere in between sort of like a bar chart and an area chart, but I think it makes it clear and easy to read. Also, because I have this stuff set in, I don't need a line across the bottom. Then I have something that reads the dates, and then what it's going to do is it's going to put in the January date. It's starting on a January because the days that starts on January. Then it skips to every 12th row. So it let me know when the first of the year starts. Right down here, that's where it places the dates.
I have to re-create the variables here, but I do them for only every 12th case. And 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 is a thicker line and also, it puts a square cap on it. And I don't draw the ellipses anymore. And so it makes it a way of telling where the year starts and stop. Then finally, below that I have two blocks that are used for interaction. The first one is about keyPressed, and then 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 is other ways you could have done this, but this is a shortcut one. And between the two of these, you see they 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, and there's my data set.
Google searches for Georges Braque, and you see it starts at 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 what each year starts. And there's a couple things you can see here. The most important one is you see that people search for George 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 Georges 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 is 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 going to 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. And now I just have a line coming through, with the information for each month as it matches up 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 06, it's a standard deviation below average.
And here we got this spike, and we've got another spike over here. I don't really know what to make of those, but 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 in with the keyboard. And there's the right arrow, and I can stop and I can start moving the mouse, and it picks up exactly where it left off. And that's a really smooth form of interaction, especially because 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 a time plot as a way of showing the prevalence of a single quantitative variable as it changes over time.
Get unlimited access to all courses for just $25/month.Become a member
61 Video lessons · 93530 Viewers
82 Video lessons · 104385 Viewers
71 Video lessons · 76519 Viewers
56 Video lessons · 107841 Viewers
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.