Skip to content
Prev 201567 / 398506 Next

Plot and area below a line graph

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

            
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