From Lupyan Lab
Jump to: navigation, search

I will be gradually posting various cool examples of Data Visualization in R, Python, JavaScript, etc. Here are some recommended resources:



Graphing libraries


I was going to do this precise tutorial showing how to create publication-quality *useful* graphs with ggplot, but someone (thankfully) beat me to it. Psychology-type graphs using GGplot. These examples also show one way to convert between 'wide' types (bad) and 'long' types (good). For more flexible conversions check out the melt and cast functions in the reshape package written by Hadley Wickham, also the author of GGPlot.

Joe Fruehwald's GGPlot tutorial. Notice in particular the graphs that use an interaction factor, e.g., factor=subj:block)

Another excellent set of examples with an emphasis on displaying within-subject error bars (something most people do incorrectly). The R Cookbook site has some other excellent tutorials on ggplot.

It can be annoying to figure out how to set the attributes (font, size, etc.) of various graph attributes. Here are some descriptions of ggplot theme definitions, and examples of modifying ggplot legends


Plotting a 3d trajectory from some points using splines (in R)

x <- splinefun(1:10, c(25,12,2,2,1,1,4,10,12,14)) #splinefun fits a spline 
y <- splinefun(1:10, c(32,25,12,2,2,2,5,7,8,10))
z <- splinefun(1:10, c(40,32,25,12,10,12,25,32,40,44))

times <- seq(1, 10, len=200)
plot3d(x(times), y(times), z(times), type="l",xlab="x",ylab="y",zlab="z",col="red")

If you want to plot multiple trajectories on the same graph, add additional ones like so:

plot3d(x2(times), y2(times), z2(times), type="l",add=TRUE,col="green")
plot3d(x3(times), y3(times), z3(times), type="l",add=TRUE,col="red")

You can spin the graph around using the mouse and zoom-in/out using the mousewheel. Save it using rgl.snapshot. See ?rgl.snapshot for info on syntax.

3d trajectory from a set of points
Personal tools
Download and Install
Notes for each class - will be updated ~week before each class.
Programming Exercises
Quick reference