[R] Setting the grid of a graph of timeseries
vittorio
vdemart1 at tin.it
Sun Dec 9 18:33:26 CET 2007
I have the following code
####################################################################
library(zoo)
miedate <- yearmon((2006)+seq(0,23)/12)
tab <- zoo(cbind(A = c(79.47, 89.13, 84.86, 75.68, 72.82, 78.87, 93.46,
78.18, 82.46, 77.25, 80.95, 84.39, 81.7, 74.76, 65.29, 60.3,
66.59, 73.19, 92.39, 65.76, 77.45, 74.22, 101.36, 100.01), B = c(77.95,
76.73, 51.2, 51.86, 51.29, 49.45, 53.88, 47.96, 55.07, 45.34,
37.07, 37.53, 47.79, 37.5, 30.35, 37.78, 34.13, 39.14, 39.89,
35.46, 36.54, 38.39, 47.33, 45.34)),miedate)
par(mai=c(0.75, 0.75, 0.1, 0.1))
my.panel <- function(...) {
fmt <- "%b-%Y" # format for axis labels
lines(...)
panel.number <- parent.frame()$panel.number
# if bottom panel
if (!length(panel.number) || panel.number == NCOL(tab)) {
# next line only if non-labelled ticks wanted for each point
axis(1, at = time(tab), lab = FALSE)
ix <- seq(1, length(tab), 3)
labs <- format(time(tab), fmt)
axis(1, at = time(tab)[ix], lab = labs[ix], tcl = -0.7, cex.axis = 0.9)
}
}
plot.zoo(tab, plot.type="single", panel=my.panel, lty=c(1,2,3,4,5,1),
lwd=c(8,2,2,2,2,8),
col=c("darkorange", "red2","darkblue","darkblue","green","midnightblue"),
xlab=" ",ylab = "euro/MWh",xaxt="n")
####################################################################
This code produces a graph with a non-decimal x-axis but by far more (human)
readable because ticks corresponds to months exactly (and not to a weird
decimal ticking!).
I would like to add a vertical grid with the same criterium.
How can I obtain this?
Ciao
Vittorio
More information about the R-help
mailing list