Limiting the x range by coord_cartesian
makes the confidence interval created by stat_smooth
disappear.
I noticed it happens with R 4.1.0 but not with R 4.0.2. The ggplot2 version I used was 3.3.5.
The first plot shows the confidence interval as a shade. The second plot should show the same confidence interval in the specified range. But with R 4.1.0, the shade disappear. Any one experiencing it?
library(ggplot2)
mtcars %>%
ggplot(aes(x = wt, y = mpg)) +
geom_point() +
stat_smooth()
mtcars %>%
ggplot(aes(x = wt, y = mpg)) +
geom_point() +
stat_smooth() +
coord_cartesian(xlim = c(3, 4))
The comments solved the problem. I summarize them as an answer. Thanks.
The issue is the R 4.1.0 problem on Windows.
See the ggplot2
issue Problem with geom_ribbon and alpha combined with coord-cartesian in R 4.1.0 on Windows.
The remedy is using ragg as a graphic backend. If you are using RStudio >= 1.4, change the graphic backend to AGG by going to General option -> General -> Graphics.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With