Skip to content

alpha in geom_stars() breaks na.value in scale_fill() #445

@dholstius

Description

@dholstius

If this is a value in ggplot2, I'm happy to file it there. Thanks for a wonderful package!

Summary

✅ Rendering finite values in a semi-transparent manner works by itself, via alpha = I(...) in geom_stars()
✅ Rendering NAs as fully transparent also works by itself, via na.value = "transparent" in, e.g., scale_fill_viridis_c()
❌ 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")

image

# This also works as intended; everything becomes 50% transparent
ggplot() + geom_stars(data = x, alpha = I(0.5))

image

# 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")

image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions