[R] mark sections on a time chart

Christof Kluß ckluss at email.uni-kiel.de
Sat Oct 20 19:21:42 CEST 2012


Hello Rui Barradas

thank you very much. That is exactly what I was looking for.

Christof

Am 20-10-2012 14:19, schrieb Rui Barradas:
> 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))
arrowsRange(start, end, at = 0, labels = seasons)




More information about the R-help mailing list