Last active
August 29, 2015 13:55
-
-
Save mages/8755590 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
set.seed(12345) | |
dat <- data.frame(category=rep(c("Food", "Drinks"),20), | |
product=rep(c("Cheese", "Wine", "Bread", "Beer"), 10), | |
year=sort(rep(c(2004:2013),4)), | |
value=sort(rnorm(40))) | |
dat <- dat[with(dat, order(category, year)),] | |
library(lattice) | |
# Change some of the default lattice settings | |
my.settings <- canonical.theme(color=FALSE) | |
my.settings[['strip.background']]$col <- "black" | |
my.settings[['strip.border']]$col<- "black" | |
xyplot(value ~ year | category, | |
groups=product, data=dat, | |
as.table=TRUE, | |
xlim=c(2003, 2016), # range of x-axis | |
scales=list(cex=c(1.1, 1.1), # increase font size | |
alternating=1, # axes labels left/bottom | |
tck = c(1,0)), # ticks only with labels | |
par.settings = my.settings, | |
cex=1.1, # change size of symbols | |
xlab=list(label="Year", fontsize=14), | |
ylab=list(label="Value", fontsize=14), | |
par.strip.text=list(col="white", font=2), | |
panel=panel.superpose, | |
panel.groups=function(x,y, group.number,...){ | |
panel.xyplot(x,y,t="b",...) | |
panel.grid(v=-1, h=-1, lty=3) | |
xt <- x[x==max(x)] # find latest year | |
yt <- y[x==max(x)] # find value at latest year | |
panel.text(xt, yt, labels=levels(dat$product)[group.number], | |
pos=4, # show labels on right side | |
...) | |
} | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment