Skip to content

Instantly share code, notes, and snippets.

@jduckles
Created April 14, 2010 02:23
Show Gist options
  • Save jduckles/365374 to your computer and use it in GitHub Desktop.
Save jduckles/365374 to your computer and use it in GitHub Desktop.
library(lattice) # ?xyplot for more info on the myriad of ways to use lattice
library(reshape) # need melt() and rename() to reshape data frame for easy plotting
# Lets plot "WorldPhones" from package datasets
wp <- rename(melt(WorldPhones), c(X1 = 'year', X2 = 'country', value = 'numphone'))
xyplot( numphone ~ year | country, data=wp, type="b", scales="free")
# To print multiple pages set layout=c(1,1) to plot 1 plot per page (or more if it makes sense)
pdf('~/path/to/mydoc.pdf', width=11, height=8.5)
xyplot( numphone ~ year | country, data=wp, type="b", scales="free", layout=c(1,1) )
dev.off()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment