Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member

Making line plots

From: Interactive Data Visualization with Processing

Video: Making line plots

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.

Making line plots

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.

Show transcript

This video is part of

Image for Interactive Data Visualization with Processing
Interactive Data Visualization with Processing

72 video lessons · 13210 viewers

Barton Poulson

Expand all | Collapse all
  1. 3m 16s
    1. Welcome
    2. What you should know
      1m 22s
    3. Using the exercise files
  2. 11m 51s
    1. Overview of data visualization
      11m 51s
  3. 11m 53s
    1. Installing Processing
      3m 38s
    2. Overview of Processing
      4m 5s
    3. Exploring libraries
      4m 10s
  4. 1h 1m
    1. Basic setup
      7m 31s
    2. Drawing points
      4m 37s
    3. Drawing lines
      5m 6s
    4. Drawing ellipses and circles
      5m 24s
    5. Drawing arcs
      6m 54s
    6. Drawing rectangles and squares
      4m 58s
    7. Drawing quadrangles
      3m 25s
    8. Drawing triangles
      2m 55s
    9. Drawing polygons
      3m 37s
    10. Drawing simple curves
      4m 54s
    11. Drawing complex curves
      6m 46s
    12. Drawing Bézier curves
      5m 38s
  5. 54m 3s
    1. Introduction to variables
      10m 44s
    2. Understanding variable scope
      6m 53s
    3. Modifying variables
      9m 8s
    4. Creating arrays
      9m 53s
    5. Modifying arrays
      6m 37s
    6. Creating strings
      7m 3s
    7. Modifying strings
      3m 45s
  6. 1h 2m
    1. Incorporating randomness
      7m 59s
    2. Using Perlin noise
      4m 24s
    3. Shuffling with Java
      3m 30s
    4. Specifying line attributes
      8m 2s
    5. Changing placement modes
      5m 45s
    6. Understanding color attributes and functions
      4m 16s
    7. Exploring color spaces
      7m 44s
    8. Using color palettes
      7m 5s
    9. Transforming the grid
      8m 38s
    10. Exploring the attribute matrix
      5m 33s
  7. 52m 7s
    1. Building code blocks
      5m 57s
    2. Writing a while loop
      3m 52s
    3. Using for loops
      5m 35s
    4. Creating conditionals
      14m 50s
    5. Working with easing
      10m 51s
    6. Creating spirals
      11m 2s
  8. 18m 55s
    1. Mouse tracking
      3m 54s
    2. Hovering and clicking
      11m 16s
    3. Understanding keyboard interaction
      3m 45s
  9. 27m 32s
    1. Specifying fonts
      6m 43s
    2. Using images
      5m 51s
    3. Playing a video loop
      6m 20s
    4. Exporting video
      3m 47s
    5. Adding sound
      4m 51s
  10. 20m 49s
    1. Creating functions
      11m 48s
    2. Creating classes and objects
      9m 1s
  11. 31m 10s
    1. Using embedded data
      5m 26s
    2. Working with appended text data
      6m 4s
    3. Working with appended tabular data
      10m 26s
    4. Reading XML data
      9m 14s
  12. 48m 17s
    1. Generating dot plots
      11m 11s
    2. Building scatter plots
      10m 0s
    3. Making line plots
      9m 55s
    4. Creating bar charts
      9m 12s
    5. Checking out examples of maps, hierarchies, and networks
      7m 59s
  13. 20m 57s
    1. Introducing some principles of 2D design
      13m 44s
    2. Understanding color theory
      7m 13s
  14. 24m 46s
    1. Interacting with zooming, rotating, and sliding
      6m 26s
    2. Implementing slicing
      6m 47s
    3. Using rollovers
      5m 58s
    4. Introducing the GUI libraries
      5m 35s
  15. 10m 35s
    1. Sharing via OpenProcessing and other sites
      3m 19s
    2. Saving as a desktop application
      2m 42s
    3. Saving as JavaScript
      1m 47s
    4. Saving as an Android application
      2m 47s
  16. 2m 38s
    1. Where to go from here
      2m 38s

Start learning today

Get unlimited access to all courses for just $25/month.

Become a member
Sometimes @lynda teaches me how to use a program and sometimes Lynda.com changes my life forever. @JosefShutter
@lynda lynda.com is an absolute life saver when it comes to learning todays software. Definitely recommend it! #higherlearning @Michael_Caraway
@lynda The best thing online! Your database of courses is great! To the mark and very helpful. Thanks! @ru22more
Got to create something yesterday I never thought I could do. #thanks @lynda @Ngventurella
I really do love @lynda as a learning platform. Never stop learning and developing, it’s probably our greatest gift as a species! @soundslikedavid
@lynda just subscribed to lynda.com all I can say its brilliant join now trust me @ButchSamurai
@lynda is an awesome resource. The membership is priceless if you take advantage of it. @diabetic_techie
One of the best decision I made this year. Buy a 1yr subscription to @lynda @cybercaptive
guys lynda.com (@lynda) is the best. So far I’ve learned Java, principles of OO programming, and now learning about MS project @lucasmitchell
Signed back up to @lynda dot com. I’ve missed it!! Proper geeking out right now! #timetolearn #geek @JayGodbold
Share a link to this course

What are exercise files?

Exercise files are the same files the author uses in the course. Save time by downloading the author's files instead of setting up your own files, and learn by following along with the instructor.

Can I take this course without the exercise files?

Yes! If you decide you would like the exercise files later, you can upgrade to a premium account any time.

Become a member Download sample files See plans and pricing

Please wait... please wait ...
Upgrade to get access to exercise files.

Exercise files video

How to use exercise files.

Learn by watching, listening, and doing, Exercise files are the same files the author uses in the course, so you can download them and follow along Premium memberships include access to all exercise files in the library.

Exercise files

Exercise files video

How to use exercise files.

For additional information on downloading and using exercise files, watch our instructional video or read the instructions in the FAQ .

This course includes free exercise files, so you can practice while you watch the course. To access all the exercise files in our library, become a Premium Member.

Are you sure you want to mark all the videos in this course as unwatched?

This will not affect your course history, your reports, or your certificates of completion for this course.

Mark all as unwatched Cancel


You have completed Interactive Data Visualization with Processing.

Return to your organization's learning portal to continue training, or close this page.

Become a member to add this course to a playlist

Join today and get unlimited access to the entire library of video courses—and create as many playlists as you like.

Get started

Already a member ?

Become a member to like this course.

Join today and get unlimited access to the entire library of video courses.

Get started

Already a member?

Exercise files

Learn by watching, listening, and doing! Exercise files are the same files the author uses in the course, so you can download them and follow along. Exercise files are available with all Premium memberships. Learn more

Get started

Already a Premium member?

Exercise files video

How to use exercise files.

Ask a question

Thanks for contacting us.
You’ll hear from our Customer Service team within 24 hours.

Please enter the text shown below:

The classic layout automatically defaults to the latest Flash Player.

To choose a different player, hold the cursor over your name at the top right of any lynda.com page and choose Site preferences from the dropdown menu.

Continue to classic layout Stay on new layout
Exercise files

Access exercise files from a button right under the course name.

Mark videos as unwatched

Remove icons showing you already watched videos if you want to start over.

Control your viewing experience

Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.

Interactive transcripts

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.

Thanks for signing up.

We’ll send you a confirmation email shortly.

Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

Keep up with news, tips, and latest courses with emails from lynda.com.

Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

submit Lightbox submit clicked
Terms and conditions of use

We've updated our terms and conditions (now called terms of service).Go
Review and accept our updated terms of service.