# Re: [R] shading an area in a edf

From: Ray Brownrigg <Ray.Brownrigg_at_mcs.vuw.ac.nz>
Date: Wed, 09 Jul 2008 09:29:48 +1200

On Tue, 08 Jul 2008, squall44 wrote:
> Hi,
>
> I've got the following edf:
>
> ***
>
> x = c(1.6,1.8,2.4,2.7,2.9,3.3,3.4,3.4,4,5.2)
> F2.5 <- ecdf(x)
> plot(F2.5,
> verticals= TRUE,
> do.p = TRUE,
> lwd=3,
> ylab = "",
> xlab = "",
> xlim = c(1,5.5))
> abline(h= (0:5)*0.2)
>
> #mean
>
> abline(v=mean(x), lwd=2)
>
> ***
>
> Now I would like to shade the two areas:
>
> http://www.nabble.com/file/p18334136/ecdf.gif
>
> Is it possible to do this without too much effort?
> Thanks for any suggestion
>
> Tobias

x = c(1.6,1.8,2.4,2.7,2.9,3.3,3.4,3.4,4,5.2) F2.5 <- ecdf(x)
plot(F2.5,

```     verticals= TRUE,
do.p = TRUE,
lwd=3,
ylab = "",
xlab = "",
xlim = c(1,5.5))
```

abline(h= (0:5)*0.2)
abline(v=mean(x), lwd=2)

# end of your stuff, now to fill the polygons mx <- mean(x)
x1 <- x[x < mx]
x1a <- rep(c(x1, mx), each=2)
y1 <- c(0, F2.5(rep(x1, each=2)), 0)
polygon(x1a, y1, col=2)
x2 <- x[x >= mx]
x2a <- rep(c(mx, x2), each=2)
y2 <- c(1, F2.5(rep(c(x1[length(x1)], x2[-length(x2)]), each=2)), 1) polygon(x2a, y2, col=2)

This seems to work even if the mean coincides with one of the x values.

HTH
Ray Brownrigg

R-help_at_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. Received on Tue 08 Jul 2008 - 21:34:29 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 08 Jul 2008 - 22:31:28 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.