How to crop the matplot graph?

How can we crop the plot until x axis = 20
basically zoom the plot from x axis = 0 until x axis = 20 and crop the rest

Also, please let me know why did the origin got cropped

Please find the reprex and screenshot attached

library(tidyverse)
mean_sim = 2.7
N = 10

up_lmt <- (max(1:N) * 2 * mean_sim)

# Setting x axis
u <- seq(from = 0,
         to = up_lmt,
         length.out = 1e+3)

## Curve simulation
v <- sapply(X = 1:N,
            FUN = function(i) dnorm(x = u,
                                    mean = (i * mean_sim),
                                    sd = i))
matplot(x = u,
        y = v,
        type = "l",
        lty = 1,
        col = rainbow(n = 10),
        xlab = "x axis",
        ylab = "y axis",
        main = "Accumulating curves")
legend(x = "topright",
       title = "Curve number",
       legend = 1:N,
       inset = -.05,
       col = rainbow(n = 10),
       bty = "n",
       lty = 1)

Add xlim=c(0,20) as an additional argument to your matplot call to set the x-range of the plot. Values below 0 on the x-axis haven't been cropped. The minimum u value in your data is u=0. If you set u so that it starts at a lower value, say, -1, then the plotted data will start at -1 instead of 0.

1 Like

Thanks for solution.
value of u is positive and that means should beseen within the right hand side of "u"

Could you please help me understand