When applying range limits to scale_y_*, this affects the data used itself. https://ggplot2.tidyverse.org/articles/faq-bars.html#axes-and-axis-limits
This might be the answer you're looking for.
library(ggplot2)
ggplot(
data = economics,
aes(x = date, y = pop)
) +
geom_rect(
mapping = aes(
xmin = as.Date("1990", "%Y"),
xmax = as.Date("2000", "%Y"),
ymin = 1,
ymax = 400000
),
fill = "grey90",
alpha = 0.25
) +
geom_line() +
theme_minimal() +
scale_y_log10() +
coord_cartesian(ylim = c(2e5, 4e5))