Skip to content
Prev 308504 / 398506 Next

mark sections on a time chart

Hello,

The function below requires package plotrix and is far from fully 
tested, but it might do what you want.


library(zoo)


arrowsRange <- function(from, to, at = 1, labels = NULL,
     length = 1/8, horizontal = TRUE, border = FALSE, ...){
     require(plotrix)
     f1 <- function(){
         if(horizontal)
             arrows(from, at, to, at, length = length, code = 3, ...)
         else
             arrows(at, from, at, to, length = length, code = 3, ...)
     }
     f2 <- function(){
         f1()
         if(horizontal){
             x <- rowMeans(cbind(from, to))
             y <- at
         }else{
             x <- at
             y <- rowMeans(cbind(from, to))
         }
         boxed.labels(x, y, labels = labels, border = border)
     }
     if(is.null(text)) f1() else f2()
}


# Make up some test data
set.seed(9365)
z <- zoo(cumsum(rnorm(365)))
index(z) <- Sys.Date() + 1:365
start <- as.Date(c("2012-12-21", "2013-03-21", "2013-06-22"))
end <- as.Date(c("2013-03-20", "2013-06-21", "2013-09-21"))
seasons <- c("Winter", "Spring", "Summer")

plot(z)
abline(v = c(start[1], end))


Hope this helps,

Rui Barradas

Em 20-10-2012 07:33, Christof Klu? escreveu: