Search code examples
rplotcurve

Extend curve to touch box


I want to draw a function in R, for example

f <- function(x) log(x)
curve(f, c(0, 1))

This gives below: enter image description here

How can I extend the curve to touch the box?

Note: I want to retain the four percent range extension of:

xaxs = "r"

Solution

  • Try something like

    curve(f, from=0, to=1.1, n=1001, ylim=c(-4,0), xlim=c(0,1))
    

    to give a curve like

    enter image description here

    On the top right, the to=1.1 extends the curve but the xlim=c(0,1) truncates it

    On the bottom left the n=1001 extends the curve downwards in the direction of x=0 and y=-infinity by adding more finite points but the ylim=c(-4,0) truncates it