On 06/06/2013 10:41 AM, Roland Pape wrote:
Dear list,
I have two time series of temperatures from different sites plotted in the same
diagram and would like to color the area between the curves differently,
dependent on whether site 1 is cooler than site 2 (colored let's say in blue)
or warmer (red). While polygone() works fine to color the enclosed area in
general, I'm struggling with this conditional coloring. Any help is greatly
appreciated!
Suppose the series are named "site1" and "site2", and they have common
times in a variable "times". Then the following should do what you want:
smaller <- pmin(site1, site2)
plot(x, site1, ylim = range(c(site1, site2)), type="n")
polygon(c(x, rev(x)), c(smaller, rev(site1)), col="red")
polygon(c(x, rev(x)), c(smaller, rev(site2)), col="blue")
If the times for the two series are different it's a little harder;
first you need to give them common times, and that will depend on how
you decide to evaluate the values between observations. Probably linear
interpolation (using approx()) is fine, but it's up to you.
Duncan Murdoch
______________________________________________
R-help@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.