You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to produce figures with geom_raster() that have:
0% opacity for NA values; and
50% opacity for finite values; with
fill colors for (continuous) finite values varying by value.
I thought that the code below would achieve that, but supplying alpha = I(0.5) in geom_raster(...) seems to override the intent of supplying na.value = "transparent" in scale_fill_continuous(...).
My expectation is that "50% opaque 'transparent'" should be identical to "transparent", not to "50% opaque white".
Reprex
library(tidyverse)
# use `faithfuld` but substitute `NA` for values less than 0.01df<- mutate(faithfuld, density= if_else(density<0.01, NA_real_, density))
p<- ggplot(df, aes(waiting, eruptions))
# - as expected: all NAs are 0% opacityp+ geom_raster(aes(fill=density)) + scale_fill_continuous(na.value="transparent")
# - as expected: finite values are 50% opacity# - not as expected: NAs are 50% (?) white rather than fully transparentp+ geom_raster(aes(fill=density), alpha= I(0.5)) + scale_fill_continuous(na.value="transparent")
The text was updated successfully, but these errors were encountered:
I can see why this can appear baffling. The reason is that you are setting the transparency, not applying it. "transparent" is simply white with an alpha of zero. When you set the alpha of this to 0.5 it becomes semi-transparent white.
You can get what you want by using stage() to modify the calculated colours:
Description
I'm trying to produce figures with
geom_raster()
that have:NA
values; andI thought that the code below would achieve that, but supplying
alpha = I(0.5)
ingeom_raster(...)
seems to override the intent of supplyingna.value = "transparent"
inscale_fill_continuous(...)
.My expectation is that "50% opaque 'transparent'" should be identical to "transparent", not to "50% opaque white".
Reprex
The text was updated successfully, but these errors were encountered: