Dear all,
I am struggling to modify the axis labels/ticks in a panel provided to
xyplot.
To begin with, I do not know the equivalent of the xaxt="n" directive for
panels that would set the stage for no default x axis being drawn.
My goal is to draw ticks and custom formatted labels at certain hours of the
week.
When I execute the code below, I get an error message in the plot window
that suggests a problem with some args parameter.
A second problem concerns the shaded rectangles I try to draw. Clearly, the
range returned by par('usr') does not correspond to the true y ranges.
Any help would be greatly appreciated,
Thanks,
Markus
PS I am using R version 2.10.0 on MACOS and the lattice package version
0.18-3 (latest)
------------------------------------------------------------------------------------
library(lattice);
#multivariate time series, one row for each hour of the week:
Xwide = cbind.data.frame(time=as.POSIXct("2010-09-06 00:00:00 EDT") +
(0:167)*3600, Comp.1= sin(2*pi*7*(0:167)/168), Comp.2 =
cos(2*pi*7*(0:167)/168));
#to pass this to xyplot, first need to reshape:
Xlong <- reshape(Xwide, varying = c(2:3), idvar = "time", direction="long",
timevar = "PC");
#get descriptive shingle labels
Xlong[,"PC"] <- factor(Xlong[,"PC"], labels = paste("PC",1:2));
xyplot(Comp ~ time | PC ,data = Xlong, pane1l = WeekhourPanel, scales =
list(x=list(at = Hours24-4*3600,
labels=as.character(format(Hours24-4*3600,"%H")))));
WeekhourPanel <- function(x,y,...){
r <- range(x);
#print(r)
Hours8 <- seq(r[1], r[2], by=8*3600);
Hours24 <- seq(r[1]+12*3600, r[2], by=24*3600)
#axis.POSIXct(1, at= Hours8, format="%H");
panel.xyplot(x,y, type="l", ...);
panel.grid(0,3);
panel.abline(v= Hours24-4*3600, lty=2, col = rgb(0,0,1,0.5));
panel.abline(v=Hours24+6*3600, lty=2, col = rgb(0,1,0,0.5));
bb <- par('usr')
y0 <- bb[3];
for (i in seq(r[1], r[2], by=48*3600)) panel.rect(xleft=i, ybottom=y0,
xright=i+24*3600-1, ytop=bb[4], col = rgb(0.75,0.75,0.75,0.3), border = NA);
panel.axis(1, at= Hours24-4*3600,
labels=as.character(format(Hours24-4*3600,"%H")));
#panel.axis(1, at= Hours24+6*3600, labels=format(x,"%H"));
#panel.axis(3, at= Hours24, labels=format(x,"%a"), line = -1, tick =
FALSE);
}
[[alternative HTML version deleted]]
______________________________________________
[email protected] 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.