[R] Polygon question

Muhammad Rahiz muhammad.rahiz at ouce.ox.ac.uk
Thu Jun 16 23:35:06 CEST 2011


Hi all,

I have the following script which fills the values which are less than
the mean of a given timeseries.

If you look closely, the colored regions are "out of line".

Any suggestions how I can rectify this?

Thanks

Muhammad


# -----
#rm(list=ls())

x <- abs(rnorm(100))
tt <- 1:100

m <- mean(x)
w  <- which(x>=m)

x1 <- x ; x2 <- x ; x3 <- x
x1[w] <- m
x2[1:length(x)] <- m

tx <- c(tt,rev(tt)) ; ty <- c(x1,rev(x2))

par(mfrow=c(2,1))
yy <- c(0,3)	# y-limit

plot(tt,x,type="l",ylim=yy)
abline(h=m)

plot(tx,ty,type="n",ylim=yy)
polygon(tx,ty,col="red")
lines(x)
# -----



More information about the R-help mailing list