Skip to content
Back to formatted view

Raw Message

Message-ID: <alpine.DEB.2.00.0911251228270.7292@paninaro.stat-math.wu-wien.ac.at>
Date: 2009-11-25T11:29:41Z
From: Achim Zeileis
Subject: Plot and area below a line graph
In-Reply-To: <7bb0a5f80911250322t3b243cc5h870df730eed63636@mail.gmail.com>

On Wed, 25 Nov 2009, Jose Narillos de Santos wrote:

> Imagine I have a variable X
>
> I use plot (X, type="l").
>
> I want to "show" with colour the area between "the line of X" and the Zero
> Axis.
>
> So that if X have negative values the colored area will be below zero.
>
> I?m trying to make this with polygons() but I?m not able....
>
> Can you guide me to do it?

Maybe something like this?

## artificial random walk
set.seed(123)
x <- cumsum(rnorm(100))

## plot
plot(x, type = "l")

## add shaded polygon
polygon(c(1, 1:100, 100), c(0, x, 0), col = "lightgray")

## zero axis
abline(h = 0, lwd = 2, col = "blue")

hth,
Z

>
> The other question is how can I show "the zero axis" in a plot?
>
> 	[[alternative HTML version deleted]]
>
>