stars
stars copied to clipboard
alpha in geom_stars() breaks na.value in scale_fill()
If this is a value in ggplot2
, I'm happy to file it there. Thanks for a wonderful package!
Summary
:white_check_mark: Rendering finite values in a semi-transparent manner works by itself, via alpha = I(...)
in geom_stars()
:white_check_mark: Rendering NA
s as fully transparent also works by itself, via na.value = "transparent"
in, e.g., scale_fill_viridis_c()
:x: Combining the two does not work; the former seems to "override" or obviate the latter
Smallish reprex
# Setup
library(stars)
library(ggplot2)
x <- read_stars(system.file("tif/L7_ETMs.tif", package = "stars"))
x[[1]][x[[1]] < 30] <- NA # Set some values to be NA
# This works; NAs become fully transparent
ggplot() + geom_stars(data = x) + scale_fill_viridis_c(na.value = "transparent")
# This also works as intended; everything becomes 50% transparent
ggplot() + geom_stars(data = x, alpha = I(0.5))
# The combination does not work---NAs become white instead of fully transparent
ggplot() + geom_stars(data = x, alpha = I(0.5)) + scale_fill_viridis_c(na.value = "transparent")
Thanks! Seems a ggplot2
issue, as stars
simply calls, for this case
# library(tibble)
ggplot() + geom_raster(data = as_tibble(x), aes(x = x, y = y, fill = L7_ETMs.tif), alpha = 0.5) +
scale_fill_viridis_c(na.value = "transparent")
Thank you, @edzer. An interpretation and a functional solution have been provided by @thomasp85 at https://github.com/tidyverse/ggplot2/issues/4630.
Closed too soon. When trying to translate that solution (for geom_raster()
) back to geom_stars()
, I get this error:
Error: Aesthetics must be valid data columns. Problematic aesthetic(s): fill = stage(...).
Did you mistype the name of a data column or forget to add after_stat()?
I can modify the reprex above or post a new one here as soon as I can (not immediately), if that's helpful.