Skip to content

geom_spatraster with alpha scaled by different layer to fill #154

@claudehspencer

Description

@claudehspencer

Just wondering if the following approach was possible in tidyterra.

I have a spatraster with a layer for prediction value and another layer for standard error, and I want to plot using one layer to scale fill and the other to scale alpha. The current approach uses geom_tile after converting spatraster to a dataframe.

library(tidyterra)
library(ggplot2)

x <- rast(array(data = rnorm(120, 0, 1), dim = c(5, 5, 2)))
names(x) = c("prediction", "se")

xdf <- as.data.frame(x, xy = T)

ggplot() +
  geom_tile(data = xdf, aes(x = x, y = y, fill = se, alpha = prediction)) +
  scale_alpha_continuous(range = c(0, 1)) +
  scale_fill_gradient(low = "white", high = "deeppink3") +
  theme_minimal()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions