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]]
______________________________________________
[email protected] 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.