Dennis,

If I understand correctly, you should be able to do something like this
(example with exponential decay):

these.x <- (1:10)/10

plot(these.x,exp(-these.x),type="l")  # create a basic plot for starting
point
this.usr <- par("usr")    # get the plotting region limits
# they are xleft, xright, ybottom, ytop

# for shading lower region
these.x2 <- c(this.usr[1],these.x,this.usr[2])   # an updated x-axis vector
polygon(x=c(this.usr[1],these.x2,this.usr[2]),
        y=c(this.usr[3],exp(-these.x2),this.usr[3]),
        col="gray",border=NA)

# for shading upper region
these.x2 <- c(this.usr[1],these.x,this.usr[2])
polygon(x=c(these.x2,this.usr[2]),
        y=c(exp(-these.x2),this.usr[4]),
        col="gray",border=NA)

# to make the plot frame more clear you may want to add
box()

Basically polygon() is able to draw a shape that has your desired curve for
one side, you just have to give it enough points to get a smooth curve (all
it took in this case was 10).  In reality it is drawing little line segments
between all the points, similar in a way to your proposal, but much faster
and simpler.

Exactly what you assign to x and y in polygon() will depend on if you curve
increases or decreases with x, or is some kind of paraboloid type thing.
but the same basic idea applies.  You don't need to use a bunch of polygons,
one will do.

Hope that helps,
Andy


On Wed, Mar 24, 2010 at 3:23 PM, Dennis Fisher <fisher@plessthan.com> wrote:

> Colleagues
>
> OS 10.5
> R: 2.10.1
>
> I have a simple x-y plot for which I would like to shade the lower (or
> upper) part of the interior region (i.e., the area bounded by the axes).  If
> the delineation between top and bottom were linear, it would be use to use
> the polygon function.  However, the delineation is a curve (which I can
> describe by an equation).  In theory, I could divide the x-axis into a large
> number of regions, then draw a series of polygons side by side, the top /
> bottom borders of which are lines.  Is there a more elegant solution?
>
> Dennis
>
>
> Dennis Fisher MD
> P < (The "P Less Than" Company)
> Phone: 1-866-PLessThan (1-866-753-7784)
> Fax: 1-866-PLessThan (1-866-753-7784)
> www.PLessThan.com
>
> ______________________________________________
> 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.
>

	[[alternative HTML version deleted]]

