Re: [R] Polygon question

2011-06-17 Thread Greg Snow
Does this do what you want?

x <- abs(rnorm(100))
tt <- 1:100
m <- mean(x)
par(mfrow=c(2,1))
yy <- c(0,3)# y-limit
plot(tt,x,type="l",ylim=yy)
abline(h=m)
clip(0,100,0,m)
polygon( c(1,tt,100), c(m,x,m), col='red' )


-- 
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.s...@imail.org
801.408.8111


> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-bounces@r-
> project.org] On Behalf Of Muhammad Rahiz
> Sent: Thursday, June 16, 2011 3:35 PM
> To: x.r-help
> Subject: [R] Polygon question
> 
> 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)
> # -
> 
> __
> 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.

__
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.


Re: [R] Polygon question

2011-06-17 Thread Uwe Ligges
Well you need to recalculate the x values and need to interpolate for 
the position where you lines cross the m lines 


Uwe Ligges




On 16.06.2011 23:35, Muhammad Rahiz wrote:

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)
# -

__
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.


__
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.


[R] Polygon question

2011-06-16 Thread Muhammad Rahiz

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)
# -

__
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.