There is an example in the example section of the ?xyplot.zoo help page
in the zoo package.
On Mon, Jan 12, 2009 at 8:16 PM, Josip Dasovic <jjd9 at sfu.ca>
wrote:> Hello:
>
> I've come to a dead-end in my search for a solution to a graphing
problem that I am encountering. I have used xyplot (from the lattice package)
successfully to plot 36 time-series plots (lines) of under-5 mortality for a set
of countries in Sub-Sarahan Africa.
>
> What I would now like to do is to add vertical bands (rectangles) that
correspond to time-periods during which each of the 36 countries was at war,
which would be different for each of the 36 panels. The effect I'd like to
produce is similar that found here:
http://thinkorthwim.com/2007/09/12/recession/ (but with 36 panels, each of which
has a different period(s) shaded).
>
> I've done this successfully one plot at a time with the simple plot
commmand (using polygon after having first drawn the line plot), but am having
difficulty replicating it with xyplot.
>
> Here is some sample code (with 4 countries and 10 years), which is as far
as I've been able to get:
>
>
> library(lattice)
>
df<-data.frame(c(u5cmr=round(runif(40)*100)),country=c(rep("Angola",10),
rep("Benin",10), rep("Botswana",10), rep("Burkina
Faso",10)), year=rep(1991:2000,4))
> names(df)<-c("u5cmr", "country", "year")
> xyplot(u5cmr ~ year | country , ylab = "U5 cmr (per thousand)",
data = df, type = "l", lty = 1, col ="red",
xlab="Year", as.table=T, lwd=2)
>
>
> R version 2.7.2 Patched (2008-09-20 r47259)
> on Mac OS 10.5
>
> Thanks,
> Josip
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>