Sunday, March 17, 2013

R Knoblauch/Maloney - MPDiR - Figure 2.1

  • rebuild some graphics from the book Knoblauch/Maloney: Modeling Psychophysical Data
  • from chapter 2 (Modeling), plotting age dependence of threshold for each level combination of Mtype and Sex using ggplot2 (page 27)
  • instead of the two panels we use two smooth() layers, loess is the default method for group sizes < 1000, so we only have to tell ggplot to use "lm" as method for one layer

  • we set se to F (se=F) in both of them which prevents the convidence intervals from being plotted

  • size, linetype, and colour are the corresponding parameters to lwd, lty, and col respectively

  • a nice list of line types and shapes of points

  • to plot a separate figure for every combination we use facet_wrap()

library(MPDiR)
data(Motion)
library(ggplot2)
ggplot(Motion, aes(x=LnAge,y=LnThresh)) + 
  geom_point() +
  geom_smooth(method="lm",se=F) +
  geom_smooth(se=F, size=2, linetype=2, colour="black") +
  facet_grid(Sex ~ Mtype,as.table=T)