How do I correctly use the alpha
aesthetic with geom_spatraster
?
#113
-
Hi, I am unable to use the Here is an easy example. How can I correctly use
|
Beta Was this translation helpful? Give feedback.
Answered by
dieghernan
Sep 22, 2023
Replies: 1 comment
-
Hi, You can do it using computed variables (i.e.
library(terra)
#> terra 1.7.46
library(tidyterra)
#>
#> Attaching package: 'tidyterra'
#> The following object is masked from 'package:stats':
#>
#> filter
library(ggplot2)
r1 <- rast(nrows = 50, ncols = 50)
values(r1) <- runif(ncell(r1))
ggplot() +
geom_spatraster(data = r1, aes(fill = lyr.1)) +
scale_fill_continuous() +
theme_void() # With alpha, use computed variable value
ggplot() +
geom_spatraster(data = r1, aes(fill = lyr.1, alpha = after_stat(value))) +
scale_fill_continuous() +
scale_alpha(range = c(0.1, 0.5)) +
theme_void() Created on 2023-09-22 with reprex v2.0.2 |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
jlegewie
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi,
You can do it using computed variables (i.e.
value, lyr
). In this case you are using the name of the layer, that does not work. See the docs: