Skip to content

Instantly share code, notes, and snippets.

@smc-dta
Forked from mages/sample_data_phones_films.R
Created June 13, 2014 20:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save smc-dta/2f0dae43728459edb646 to your computer and use it in GitHub Desktop.
Save smc-dta/2f0dae43728459edb646 to your computer and use it in GitHub Desktop.
set.seed(1234)
dat <- data.frame(
product=c(rep("Mobile",2),
rep(c("Smartphone", "Mobile"),3),
rep(c("Video rental shop"),3),
rep(c("Video rental shop",
"Online movie rental"),2)),
year=c(2008:2010, 2010, 2011, 2011, 2012, 2012,
2008:2010, 2011, 2011, 2012, 2012),
category=c(rep("Phone", 8), rep("Film", 7)),
price.change=rnorm(15, 0, 0.1)+0.1)
dat$product <- with(dat, factor(product,
levels=levels(product)[c(1,3,4,2)],
ordered=TRUE))
library(lattice)
my.settings <- canonical.theme(color=FALSE)
my.settings[['strip.background']]$col <- "black"
my.settings[['strip.border']]$col<- "black"
barchart(price.change ~ factor(year) | product,
data=dat,
layout=c(2,2),
par.settings = my.settings,
par.strip.text=list(col="white", font=2),
horizontal=FALSE, origin=0,
scales=list(cex=c(1.1, 1.1)), # increase font size
xlab=list(label="Year", fontsize=14),
ylab=list(label="Price change", fontsize=14),
panel=function(x,y,...){
panel.abline(h=0)
panel.barchart(x,y,...)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment