[R] shading in overlap between two ranges
Graves, Gregory
ggraves at sfwmd.gov
Thu Jun 2 17:04:30 CEST 2011
I have 2 datafiles 'target' and 'observed' as shown below (I will gladly
email these 2 small files to whomever). X25. And X75. Indicate the
value of 25th and 75th-percentile of the target ('what should be') and
the observed ('what is'). The i.value is simply the month.
> target
X i.value X25. X75.
1 one.month 1 10.845225 17.87237
2 one.month 2 12.235813 19.74490
3 one.month 3 14.611749 23.44810
4 one.month 4 17.529332 28.09647
5 one.month 5 19.458738 30.56936
6 one.month 6 15.264505 28.29333
7 one.month 7 12.370369 23.35455
8 one.month 8 12.471224 21.82794
9 one.month 9 9.716685 17.28762
10 one.month 10 6.470568 12.49830
11 one.month 11 6.180560 14.24961
12 one.month 12 9.673738 15.79208
> observed
X i.value X25. X75.
1 one.month 1 19.81000 27.63500
2 one.month 2 23.64062 30.09125
3 one.month 3 26.04865 35.99104
4 one.month 4 32.02625 41.50958
5 one.month 5 34.74479 47.75958
6 one.month 6 37.48885 46.56448
7 one.month 7 30.06740 40.10146
8 one.month 8 26.14917 39.49458
9 one.month 9 14.12521 32.39406
10 one.month 10 11.04125 23.55479
11 one.month 11 13.14917 23.56833
12 one.month 12 17.17938 27.02458
The following plots 4 lines on one graph. The area between the two red
lines represents the target 'zone', and the area between the two black
lines is the observed 'zone'.
with(target, plot(X25.~i.value,ylim=c(0,55),type='l',col='red'))
par(new=T)
with(target, plot(X75.~i.value,ylim=c(0,55),type='l',col='red'))
par(new=T)
with(observed, plot(X25.~i.value,ylim=c(0,55),type='l'))
par(new=T)
with(observed, plot(X75.~i.value,ylim=c(0,55),type='l'))
par(new=F)
Ideally, the target and the observed should overlap in every month -
they don't. The desire is to visually accentuate the amount of overlap
by shading in the area where these two "zones" overlap. How would you
do that? Note, that in some of these characterizations, the overlap
wanders in and out [I already have routines that calculate the percent
of overlap, but I have been requested to find a way to shade the
overlap.]
More information about the R-help
mailing list