Skip to content

Instantly share code, notes, and snippets.

@coolbutuseless
Created February 13, 2020 10:39
Show Gist options
  • Save coolbutuseless/80f38842b9bdb0d591c66a65fcce950c to your computer and use it in GitHub Desktop.
Save coolbutuseless/80f38842b9bdb0d591c66a65fcce950c to your computer and use it in GitHub Desktop.
stacking alpha
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Simple function to create a plot with N overlapping rectangles with
# each having an alpha of 1/N
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
stack_alpha <- function(N) {
plot_df <- tibble(
x = seq(0.45, 0.55, length.out = N),
y = seq(0.45, 0.55, length.out = N),
alpha = 1/N
)
ggplot(plot_df) +
geom_tile(aes(x, y, alpha = I(alpha)), fill = 'black',
width=0.5, height = 0.5, colour = NA) +
theme_bw()
}
stack_alpha(10)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment