My working code now contains an error I cannot correct..

This code was working and now I keep getting the error...Error in xy.coords(x, y, xlabel, ylabel, log) : 'x' and 'y' lengths differ

xvals <- seq(from = -4*sigma, to = 4*sigma, length.out = 100)
ndens <- dnorm(xvals, mean = mu, sd = sigma)

plot(xvals, ndens, type = "l")

VaR99 <- qnorm(0.99, mean = mu, sd = sigma)
ES99 <- ESnorm(0.99, mu = mu, sd = sigma)

abline(v = VaR99, col = "red")
abline(v = ES99, col = "green")

I can't reproduce your error.

which line does it occur on ?
immediately after plot ?
if so what is str(xvals) and str(ndens) for you ?

Here is the output I get:
xvals <- seq(from = -4sigma, to = 4sigma, length.out = 100)
ndens <- dnorm(xvals, mean = mu, sd = sigma)
plot(xvals, ndens, type = "l")
*Error in xy.coords(x, y, xlabel, ylabel, log) : *

  • 'x' and 'y' lengths differ*
    VaR99 <- qnorm(0.99, mean = mu, sd = sigma)
    ES99 <- ESnorm(0.99, mu = mu, sd = sigma)
    abline(v = VaR99, col = "red")

str(xvals) ?
and str(ndens) ?