[R] mark sections on a time chart

Rui Barradas ruipbarradas at sapo.pt
Sat Oct 20 14:19:22 CEST 2012


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:
> Hi
>
> is there a comfortable way to mark periods on time chart (axis.Date)?
>
> To do it with arrows(...), seems to be irritating.
>
> I want to have something like
>
> <---winter--><--spring--><--summer-->
>
> thx
> Christof
>
> ______________________________________________
> 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.




More information about the R-help mailing list