Re: [R] plot with different color

From: P Ehlers <ehlers_at_math.ucalgary.ca>
Date: Sat 03 Jun 2006 - 10:18:28 EST

Greg,

It might be better to use ylim = c(min(x), 0) in place of ylim = c(-4, 0). I don't think plt can take negative values.

Peter Ehlers

Greg Snow wrote:

> Here is one approach. It uses the function clipplot which is shown
> below (someday I will add this to my TeachingDemos package, the
> TeachingDemos package is required).
>
> An example of usage:
>
>
>>x <- rnorm(1:100)
>>plot(x, type='l',col='red')
>>clipplot( lines(x, col='blue'), ylim=c(-4,0) )
>
>
> Hope this helps,
>
> The function definition is:
>
> clipplot <- function(fun, xlim=par('usr')[1:2],
> ylim=par('usr')[3:4] ){
> old.par <- par(c('plt','xpd'))
>
>
> if( length(xlim) < 2 ) stop('xlim must be a vector with at least 2
> elements')
> if( length(ylim) < 2 ) stop('ylim must be a vector with at least 2
> elements')
>
> if( !require(TeachingDemos) ) stop('TeachingDemos package needed')
>
> xl <- range(xlim)
> yl <- range(ylim)
>
> pc <- cnvrt.coords(xl,yl)$fig
>
> par(plt=c(pc$x,pc$y),xpd=FALSE)
>
> fun
>
> par(old.par)
> box() # need to plot something to reset
>
> }
>
>
>



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Sat Jun 03 10:30:42 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Sat 03 Jun 2006 - 14:10:26 EST.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.