Re: [R] color area between two time-series via polygon()?

From: jim holtman <jholtman_at_gmail.com>
Date: Sun, 24 Feb 2008 21:12:16 -0500

I think you have to change one statement in your program:

 xx <- cbind(time(z[,1]),rev(time(z[,2])))

On Sun, Feb 24, 2008 at 7:44 PM, <Jan.Verbesselt_at_csiro.au> wrote:
> Hi all,
>
>
>
> I would like to color the area between two time-series. I tried it by
> using the polygon() function but I keeps drawing lines between beginning
> and end points.
>
> Is there another more appropriate function or how could I close the
> polygon at the end en the beginning of the time series (e.g., drawing a
> straight line)?
>
>
>
> The following doesn't plot a polygon between the two time-series:
>
> z <- ts(matrix(rnorm(200), 100), start=c(1961, 1), frequency=12)
>
> plot(z, plot.type="single", lty=1:2)
>
> xx <- cbind(time(z[,1]),rev(z[,2]))
>
> yy <- cbind(as.vector(z[,1]),rev(as.vector(z[,2])))
>
> polygon(xx,yy, col="gray", border = "red")
>
>
>
> I would like to make it look like this (but then for time series)
>
> n <- 100
> xx <- c(0:n, n:0)
> yy <- c(c(0,cumsum(stats::rnorm(n))), rev(c(0,cumsum(stats::rnorm(n)))))
> plot (xx, yy, type="n", xlab="Time", ylab="Distance")
> polygon(xx, yy, col="gray", border = "red")
>
>
>
> Thanks for your help,
>
> Jan
>
>
>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> 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.
>

-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem you are trying to solve?  Tell me what you want to
do, not how you want to do it.

______________________________________________
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.
Received on Mon 25 Feb 2008 - 02:18:43 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Mon 25 Feb 2008 - 03:30:17 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive