Now that you have data being loaded and you can look around the file a bit using the console, let’s have way more fun. This brief exercise is simply to show you how to plot a time series. RStudio is often used by researchers for its rich away of graphing tools. Learning to use these tools is really straightforward, and so let’s have fun with our keystrokes data now.

First, I’m going to assume you have keystrokes loaded up, as in the prior exercise. Here’s our first, simple plot. We just need to call the plot function.

plot(keystrokes$keystroke_in_ms)

Here you can see that it just plots in order the sequence of numbers in the keystrokes table. Notice that we’ve now used something new here, with the dollar sign. Our keystrokes table has a single column of reaction time (keystroke speeds). RStudio lets us name these columns and refer to them with the dollar sign, like this: datacolumnName. In our case, our data table is called keystrokes, and our column name is called keystroke_in_ms, so we have: keystrokeskeystroke_in_ms. This will come in handy later. Note that I named the column this in the file itself. If you open the *.csv file (e.g., with Notepad) you’ll see, in the header, this column name.

Anyway, you’ll also notice that this plot is pretty boring. It uses a default “Index” along the x-axis label, and the variable name (using the dollar sign) in the y-axis label. Boo. Let’s change this to make it somewhat more snazzy:

plot(keystrokes$keystroke_in_ms,xlab='Time (keystroke)', ylab='Keystroke speed (ms)')

Notice we have changed the axis labels to something more readable (with plot options xlab and ylab). Now let’s change some other features of the plot. Let’s “connect the dots”:

plot(keystrokes$keystroke_in_ms,xlab='Time (keystroke)', ylab='Keystroke speed (ms)',type='l')

Using type = ‘l’, we have now created a “line type” plot, which connects all the points together.

Now I’m going to reformat the code slightly and show you a few other options. In your scripts, you can easily adjust these yourself to explore different plotting strategies. Note that I format my code slightly differently here to make it more readable for you. You can make your scripts more readable this way too.

plot(keystrokes$keystroke_in_ms,
     xlab='Time (keystroke)', 
     ylab='Keystroke speed (ms)',
     type='b',
     col='blue',
     lwd=3,
     main='This is my title',
     pch=13,
     xlim=c(100,200),
     ylim=c(0,1000))

Simple exercise

Play with these options above (lwd, col, etc.) and figure out what they all mean by changing how the plot looks.

Simple exercise

In the brief introduction to time series, Rick explained three types of time series: categorical, continuous, and trial series. A categorical is a sequence of numeric codes that don’t represent ‘magnitudes.’ A continuous time series is one that is continually changing over and over, like arm movements or heart rate. A trial series is an ordered set of observations that may not reflect time perfectly, but at least reflects cognition in how it is unfolding step by step. What type of time series is this keystroke sequence of numbers: categorical, continuous, or trial series?