Hi, does anybody know how I can color the area enclosed between two curves on a plot? Thanks, ------------------------------------------------------------------- Rajarshi Guha <rxg218 at psu.edu> <http://jijo.cjb.net> GPG Fingerprint: 0CCA 8EE2 2EEB 25E2 AB04 06F7 1BB9 E634 9B87 56EE ------------------------------------------------------------------- A debugged program is one for which you have not yet found the conditions that make it fail. -- Jerry Ogdin
filling the area between two curves in a plot
3 messages · Rajarshi Guha, Thomas Petzoldt, Thomas Lumley
Rajarshi Guha wrote:
Hi, does anybody know how I can color the area enclosed between two curves on a plot?
This is possible with the polygon function. Try something like: # create some data x <- sort(runif(10, min=0, max=10)) y <- runif(10, min=2, max=5) #Polygon-Plot plot(x,y, type="n", ylim=c(0,5)) polygon(c(x[1], x, x[length(x)]), c(0, y, 0), col="green") # ... alternatively you can construct a polygon # from two separate curves with # create some more data x <- sort(runif(10, min=0, max=10)) y1 <- runif(10, min=2, max=5) y2 <- runif(10, min=0, max=2) #Polygon-Plot 2 polygon(c(x, rev(x)), c(y1, rev(y2)), density=20) Hope it helps! Thomas P.
On Thu, 19 Feb 2004, Rajarshi Guha wrote:
Hi, does anybody know how I can color the area enclosed between two curves on a plot?
There is an example of this in demo(graphics). -thomas