wilkelab / cowplot

cowplot: Streamlined Plot Theme and Plot Annotations for ggplot2
https://wilkelab.org/cowplot/
701 stars 84 forks source link

Odd problem with setting alpha in an annotate geom #180

Open simonthelwall opened 2 years ago

simonthelwall commented 2 years ago

This odd problem may be restricted to Windows. I've been trying to produce a plot with a shaded region using the annotate geom. If I set the alpha for the fill to less than 0.6, then when opening in the default image viewer for Windows the shaded area appears briefly and then disappears. The rest of the plot is still displayed and the plot displays without a problem in the viewer panel.

I've narrowed this down to a problem with cowplot by running the code below and this displays normally. I've added my session info below the reprex.


Brief description of the problem or desired feature.

``` r
library(ggplot2)
#> Warning: package 'ggplot2' was built under R version 4.0.5
# library(cowplot)
library(viridis)
#> Warning: package 'viridis' was built under R version 4.0.5
#> Loading required package: viridisLite
#> Warning: package 'viridisLite' was built under R version 4.0.5
library(lubridate)
#> Warning: package 'lubridate' was built under R version 4.0.5
#> 
#> Attaching package: 'lubridate'
#> The following objects are masked from 'package:base':
#> 
#>     date, intersect, setdiff, union

data("mtcars")

dat <- data.frame(expand.grid(seq.Date(today() - 365, to = today(), by = 1), c("a", "b", "c")))

names(dat) <- c("date", "grp")
dat$val <- runif(n = 1098)

p <- ggplot(data = dat, aes(x = date, y = val, group = grp)) + 
  facet_wrap(.~grp, ncol = 1) + 
  annotate("rect", xmin = today() - 28, xmax = today(), ymin = min(dat$val), 
           ymax = max(dat$val), alpha = .1, fill = "blue") +
  scale_fill_viridis_d("val", option = "D", begin = 0.5,
                       end = 0.1) + 
  # theme_cowplot() +
  geom_col(aes(fill = grp))
p

ggsave(p, filename = "cars.png", width = 16, height = 16, units = "cm")

Created on 2022-01-13 by the reprex package (v2.0.1)

```{r}
> devtools::session_info()
- Session info  -----------------------------------------------------------------------------------
 hash: speaking head, trophy, woman farmer: medium-light skin tone

 setting  value
 version  R version 4.0.2 (2020-06-22)
 os       Windows 10 x64 (build 19042)
 system   x86_64, mingw32
 ui       RStudio
 language (EN)
 collate  English_United Kingdom.1252
 ctype    English_United Kingdom.1252
 tz       Europe/London
 date     2022-01-13
 rstudio  1.4.1103 Wax Begonia (desktop)
 pandoc   2.11.2 @ C:/Program Files/RStudio/bin/pandoc/ (via rmarkdown)

- Packages ----------------------------------------------------------------------------------------
 package     * version date (UTC) lib source
 assertthat    0.2.1   2019-03-21 [1] CRAN (R 4.0.2)
 cachem        1.0.6   2021-08-19 [1] CRAN (R 4.0.5)
 callr         3.7.0   2021-04-20 [1] CRAN (R 4.0.5)
 cli           3.1.0   2021-10-27 [1] CRAN (R 4.0.5)
 clipr         0.7.1   2020-10-08 [1] CRAN (R 4.0.5)
 colorspace    2.0-2   2021-06-24 [1] CRAN (R 4.0.5)
 cowplot     * 1.1.1   2020-12-30 [1] CRAN (R 4.0.5)
 crayon        1.4.2   2021-10-29 [1] CRAN (R 4.0.5)
 DBI           1.1.1   2021-01-15 [1] CRAN (R 4.0.5)
 desc          1.4.0   2021-09-28 [1] CRAN (R 4.0.5)
 devtools      2.4.2   2021-06-07 [1] CRAN (R 4.0.5)
 digest        0.6.28  2021-09-23 [1] CRAN (R 4.0.5)
 dplyr         1.0.7   2021-06-18 [1] CRAN (R 4.0.5)
 ellipsis      0.3.2   2021-04-29 [1] CRAN (R 4.0.5)
 evaluate      0.14    2019-05-28 [1] CRAN (R 4.0.2)
 fansi         0.5.0   2021-05-25 [1] CRAN (R 4.0.5)
 farver        2.1.0   2021-02-28 [1] CRAN (R 4.0.5)
 fastmap       1.1.0   2021-01-25 [1] CRAN (R 4.0.5)
 fs            1.5.0   2020-07-31 [1] CRAN (R 4.0.5)
 generics      0.1.1   2021-10-25 [1] CRAN (R 4.0.5)
 ggplot2     * 3.3.5   2021-06-25 [1] CRAN (R 4.0.5)
 glue          1.4.2   2020-08-27 [1] CRAN (R 4.0.5)
 gridExtra     2.3     2017-09-09 [1] CRAN (R 4.0.2)
 gtable        0.3.0   2019-03-25 [1] CRAN (R 4.0.2)
 highr         0.9     2021-04-16 [1] CRAN (R 4.0.5)
 htmltools     0.5.2   2021-08-25 [1] CRAN (R 4.0.5)
 knitr         1.36    2021-09-29 [1] CRAN (R 4.0.2)
 labeling      0.4.2   2020-10-20 [1] CRAN (R 4.0.3)
 lifecycle     1.0.1   2021-09-24 [1] CRAN (R 4.0.5)
 lubridate   * 1.8.0   2021-10-07 [1] CRAN (R 4.0.5)
 magrittr      2.0.1   2020-11-17 [1] CRAN (R 4.0.3)
 memoise       2.0.0   2021-01-26 [1] CRAN (R 4.0.5)
 munsell       0.5.0   2018-06-12 [1] CRAN (R 4.0.2)
 pillar        1.6.4   2021-10-18 [1] CRAN (R 4.0.5)
 pkgbuild      1.2.0   2020-12-15 [1] CRAN (R 4.0.5)
 pkgconfig     2.0.3   2019-09-22 [1] CRAN (R 4.0.2)
 pkgload       1.2.3   2021-10-13 [1] CRAN (R 4.0.5)
 prettyunits   1.1.1   2020-01-24 [1] CRAN (R 4.0.2)
 processx      3.5.2   2021-04-30 [1] CRAN (R 4.0.5)
 ps            1.6.0   2021-02-28 [1] CRAN (R 4.0.5)
 purrr         0.3.4   2020-04-17 [1] CRAN (R 4.0.2)
 R6            2.5.1   2021-08-19 [1] CRAN (R 4.0.5)
 ragg          1.2.0   2021-10-30 [1] CRAN (R 4.0.5)
 remotes       2.4.1   2021-09-29 [1] CRAN (R 4.0.5)
 reprex      * 2.0.1   2021-08-05 [1] CRAN (R 4.0.5)
 rlang         0.4.12  2021-10-18 [1] CRAN (R 4.0.5)
 rmarkdown     2.11    2021-09-14 [1] CRAN (R 4.0.5)
 rprojroot     2.0.2   2020-11-15 [1] CRAN (R 4.0.5)
 rstudioapi    0.13    2020-11-12 [1] CRAN (R 4.0.5)
 scales        1.1.1   2020-05-11 [1] CRAN (R 4.0.2)
 sessioninfo   1.2.1   2021-11-02 [1] CRAN (R 4.0.5)
 systemfonts   1.0.3   2021-10-13 [1] CRAN (R 4.0.5)
 testthat      3.1.0   2021-10-04 [1] CRAN (R 4.0.5)
 textshaping   0.3.6   2021-10-13 [1] CRAN (R 4.0.5)
 tibble        3.1.5   2021-09-30 [1] CRAN (R 4.0.5)
 tidyselect    1.1.1   2021-04-30 [1] CRAN (R 4.0.5)
 usethis       2.1.3   2021-10-27 [1] CRAN (R 4.0.5)
 utf8          1.2.2   2021-07-24 [1] CRAN (R 4.0.5)
 vctrs         0.3.8   2021-04-29 [1] CRAN (R 4.0.5)
 viridis     * 0.6.2   2021-10-13 [1] CRAN (R 4.0.5)
 viridisLite * 0.4.0   2021-04-13 [1] CRAN (R 4.0.5)
 withr         2.4.2   2021-04-18 [1] CRAN (R 4.0.5)
 xfun          0.28    2021-11-04 [1] CRAN (R 4.0.5)
 yaml          2.2.1   2020-02-01 [1] CRAN (R 4.0.0)

 [1] C:/Users/simon.thelwall/Documents/R/win-library/4.0
 [2] C:/Users/simon.thelwall/Documents/R/R-4.0.2/library