The problem is that for x = 7 the y value is now 0, but for x = 8 the y value is 2.0794415, and therefore the interval between the intervals.
Instead, you can use a subset pdatto geom_area:
ggplot() +
geom_area(data = pdat[pdat$y > 2 & pdat$y < 5,], aes(x = x, y = y),
fill = "red", alpha = 0.5) +
geom_line(data = pdat, aes(x = x, y = y))

source
share