x <- seq(-pi, pi, 0.001)
y <- cos(x)
w <- fwhm(x, y)
m <- x[which.max(y)]
f <- m - w/2
t <- m + w/2
plot(x, y, type="l",
panel.first = {
usr <- par('usr')
rect(f, usr[3], t, usr[4], col = rgb(0, 1, 0, 0.4), border = NA)
})
abline(h = max(y) / 2, lty = 2, col = "gray")
Run the code above in your browser using DataLab