Data Science

Spaghetti Plots

Overview

Spaghetti plots are a useful data visualisation technique particularly in longitudinal analysis. This post provides some sample spaghetti plots together with the annotated R code used to create them. For an excellent treatment on longitudinal analysis and the role of spaghetti plots read:

Bolger, N., & Laurenceau, J.-P. (2013). Intensive Longitudinal Methods: An Introduction to Diary and Experience Sampling Research (Methodology in the Social Sciences) (p. 256). The Guilford Press. Retrieved from http://www.amazon.com/Intensive-Longitudinal-Methods-Introduction-Methodology/dp/146250678X

Example Plots

Below are some examples of spaghetti plots showing results for 3 different participants in the same longitudinal study. The thin grey lines are linear trends for all participants in the study, the orange line the overall study group trend, the thick grey line a cubic group trend and the thick blue line is the participant’s linear trend. The blue circles represents actual participant observations.

PracMinsPlot-1,

PracMinsPlot-2

PracMinsPlot-3,

Sample Code

The R code to create the spaghetti plots is below and includes annotations. As always, there may be neater ways to do some of these things, but at least here is one way that works. You can modify this code to incorporate your own data sources.

https://dl.dropboxusercontent.com/u/10069250/Wordpress/Spaghetti%20Plots/SpaghettiPlot.R

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s