[R] calculating area between plot lines

A. Marcia BARBOSA anamarciabarbosa at gmail.com
Mon Sep 6 16:30:43 CEST 2010


Hi everyone. I have these data:

probClass<-seq(0,0.9,0.1)
prob1<-c(0.0070,0.0911,0.1973,0.2949,0.3936,0.5030,0.5985,0.6869,0.7820,0.8822)
prob2<-c(0.0066,0.0791,0.2358,0.3478,0.3714,0.3860,0.6667,0.6400,0.7000,1.0000)

# which I'm plotting as follows:

plot(probClass,prob1,xlim=c(0,1),ylim=c(0,1),xaxs='i',yaxs='i',type="n")
lines(probClass,prob1)
lines(probClass,prob2)
polygon(c(probClass,rev(probClass)),c(prob2,rev(prob1)),col="red",border=NA)


Given that the total area of the plot is 1, how can I calculate the
area between the plotted lines (red polygon)? I have only found the
areapl function in the splancs package, but it doesn't work for
self-intersecting polygons..

Any help will be gratefully received. Cheers,
Márcia



More information about the R-help mailing list