ggplot(economics) +
geom_rect(
aes(
xmin = economics$date[20],
xmax = economics$date[140],
ymin = -Inf,
ymax = Inf
),
fill = "grey",
color = "grey",
alpha = 0.4
) +
geom_line(aes(x = date, y = pce))
works fine and produces the desired plot. But if one were to transform the y-axis to log10 (by using scale_y_log10())
ggplot(economics) +
geom_rect(
aes(
xmin = economics$date[20],
xmax = economics$date[140],
ymin = -Inf,
ymax = Inf
),
fill = "grey",
color = "grey",
alpha = 0.4
) +
geom_line(aes(x = date, y = pce)) +
scale_y_log10()
it gives the following error:
Warning messages:
1: In self$trans$transform(x) : NaNs produced
2: Removed 574 rows containing missing values (geom_rect).
and removes the geom_rect layer.