[R] lines - defining the range that is plotted

Duncan Murdoch murdoch.duncan at gmail.com
Fri Sep 25 08:44:36 CEST 2015

On 24/09/2015 6:26 PM, Hermann Norpois wrote:
> Hello,
> I am looking for a possibility to define something like ylim for lines. I
> thought, there might be a possibility to define the range of lines by means
> of par ("usr") but I did not find the correct syntax. In my toy example I
> would like to stop the red line at y=0.3.
> Thanks Hermann
> toy example:
> x <- seq (-3,3, by=0.1)
> y1 <- dnorm (x)
> y2 <- pnorm (x)
> plot (x,y1)
> lines (x,y2, col="red")

The clip() function does what you want.  You could use

clip(min(x), max(x), min(y2), 0.3)

before the call to lines() to get what you want.

See the example in the help page for how to restore the full region.

Duncan Murdoch

More information about the R-help mailing list