'stat_smooth(geom = 'area', ...) not generates filled area output in Windows 10

I rerun the code from this link with the version of ggplot2==3.3.5:

df <- structure(list(date = c("2022-2-1", "2022-2-2", "2022-2-3", "2022-2-4", 
"2022-2-5", "2022-2-6", "2022-2-7", "2022-2-8", "2022-2-9", "2022-2-10", 
"2022-2-11", "2022-2-12", "2022-2-13", "2022-2-14", "2022-2-15", 
"2022-2-16", "2022-2-17"), pct_change = c(4, 4, 4.04, 4.04, 4.04, 
4.44, 4.88, 4.62, 4.8, 5.2, 4.7, 5.06, 4.56, 4.8, 4.32, 4.02, 
4.01)), class = "data.frame", row.names = c(NA, -17L))

df1 <- df %>% 
  mutate_at(vars(-date), funs(./100))

df1 %>% 
  ggplot(aes(x=as.POSIXct(date), y=pct_change)) + 
  stat_smooth(
    geom = "area", 
    size = 1,
    fill = "red", 
    color = "red", 
    alpha = 0.3, 
    span = .3
  ) +
  coord_cartesian(ylim = c(.04, .0525), expand = FALSE)

It unexpectedly generates the warning messages:

geom_smooth() using method = 'loess' and formula 'y ~ x' Warning in stats::qt(level/2 + 0.5, pred$df) : NaNs produced

enter image description here

which leads to the area didn't get filled with red color as @zephryl's ouput shown:

enter image description here

How could we solve this issue? Thanks for your help at advance.

Edit 1:

I copy the chuck of code above and run reprex::reprex():

> library(ggplot2)
> library(tidyverse)
> 
> df <- structure(list(date = c("2022-2-1", "2022-2-2", "2022-2-3", "2022-2-4", 
+                               "2022-2-5", "2022-2-6", "2022-2-7", "2022-2-8", "2022-2-9", "2022-2-10", 
+                               "2022-2-11", "2022-2-12", "2022-2-13", "2022-2-14", "2022-2-15", 
+                               "2022-2-16", "2022-2-17"), pct_change = c(4, 4, 4.04, 4.04, 4.04, 
+                                                                         4.44, 4.88, 4.62, 4.8, 5.2, 4.7, 5.06, 4.56, 4.8, 4.32, 4.02, 
+                                                                         4.01)), class = "data.frame", row.names = c(NA, -17L))
> 
> df1 <- df %>% 
+   mutate_at(vars(-date), funs(./100))
> 
> df1 %>% 
+   ggplot(aes(x=as.POSIXct(date), y=pct_change)) + 
+   stat_smooth(
+     geom = "area", 
+     size = 1,
+     fill = "red", 
+     color = "red", 
+     alpha = 0.3, 
+     span = .3
+   ) +
+   coord_cartesian(ylim = c(.04, .0525), expand = FALSE)
`geom_smooth()` using method = 'loess' and formula 'y ~ x'
Warning message:
In stats::qt(level/2 + 0.5, pred$df) : NaNs produced
> 
> reprex::reprex(style = TRUE)
i Rendering reprex...
√ Reprex output is on the clipboard.

Output:

This reprex appears to crash R. See standard output and standard error for more details.

Standard output and error

Quitting from lines 23-48 (grave-cobra_reprex.spin.Rmd) 
Error in curl::curl_fetch_memory(url, handle = handle) : 
  schannel: failed to receive handshake, SSL/TLS connection failed


Solution 1:[1]

Not an answer, just too much code for a comment. On my Mac, this is not reproducible. As per comment, ideally try to use the reprex package in order to check if this is really related to your OS.

Below the code used for my reprex. If your reprex call should crash the session, please try on a different machine, if you're using reprex correctly. Sometimes reprex just doesn't work, and keeps crashing, and you need to restart R / RStudio in order to make it work again.

library(ggplot2)
library(dplyr)
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union
df <- structure(list(date = c("2022-2-1", "2022-2-2", "2022-2-3", "2022-2-4", 
                              "2022-2-5", "2022-2-6", "2022-2-7", "2022-2-8", "2022-2-9", "2022-2-10", 
                              "2022-2-11", "2022-2-12", "2022-2-13", "2022-2-14", "2022-2-15", 
                              "2022-2-16", "2022-2-17"), pct_change = c(4, 4, 4.04, 4.04, 4.04, 
                                                                        4.44, 4.88, 4.62, 4.8, 5.2, 4.7, 5.06, 4.56, 4.8, 4.32, 4.02, 
                                                                        4.01)), class = "data.frame", row.names = c(NA, -17L))

df1 <- df %>% 
  mutate_at(vars(-date), funs(./100))
#> Warning: `funs()` was deprecated in dplyr 0.8.0.
#> Please use a list of either functions or lambdas: 
#> 
#>   # Simple named list: 
#>   list(mean = mean, median = median)
#> 
#>   # Auto named with `tibble::lst()`: 
#>   tibble::lst(mean, median)
#> 
#>   # Using lambdas
#>   list(~ mean(., trim = .2), ~ median(., na.rm = TRUE))
#> This warning is displayed once every 8 hours.
#> Call `lifecycle::last_lifecycle_warnings()` to see where this warning was generated.

df1 %>% 
  ggplot(aes(x=as.POSIXct(date), y=pct_change)) + 
  stat_smooth(
    geom = "area", 
    size = 1,
    fill = "red", 
    color = "red", 
    alpha = 0.3, 
    span = .3
  ) +
  coord_cartesian(ylim = c(.04, .0525), expand = FALSE)
#> `geom_smooth()` using method = 'loess' and formula 'y ~ x'
#> Warning in stats::qt(level/2 + 0.5, pred$df): NaNs produced

Created on 2022-03-09 by the reprex package (v2.0.1)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1