[R] area between two curves, but one is not continuous
Anton Meyer
axmeyer at googlemail.com
Thu Sep 7 18:49:06 CEST 2006
Hello,
I want to colorize the area between two curves, but one of these
curves isn't continuous.
The best solution I found is the 2nd example in the help of polygon,
but how can I get no area filling for the missing data in the 2nd curve.
example:
x1 = c(1:8)
x2 = c(1:8)
y1 = c(1,5,6,1,4,5,5,5)
y2 = c(0,3,3,NA,NA,1,3,4)
plot(x1,y1,type="l")
lines(x2,y2)
for the missing parts I want no filling.
so for this examples the code would be:
polygon(c(1:3,3:1),c(y1[1:3],rev(y2[1:3])),col="green")
polygon(c(6:8,8:6),c(y1[6:8],rev(y2[6:8])),col="green")
How can I generalize this for a longer curve with more data?
AxM
More information about the R-help
mailing list