Last active
March 12, 2021 06:05
-
-
Save jonspring/67c93d510e3fe81d2924826752e6b66c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
devtools::install_github("coolbutuseless/poissoned") | |
library(poissoned) | |
# v1 | |
poisson_disc(ncols = 100, nrows = 50, cell_size = 10) %>% | |
as_tibble() %>% | |
arrange(y) %>% | |
mutate(rando = runif(n()), | |
visibility = case_when( | |
y >= 300 ~ (500-y)/200, | |
y <= 200 ~ (y)/200, | |
TRUE ~ 1 | |
), | |
color = floor(x/100)) %>% | |
filter(visibility > rando) %>% | |
ggplot(aes(y, x, color = color)) + | |
geom_point(shape = 15, alpha = 0.8) + | |
scale_color_gradientn(colours = rainbow(20), guide = NULL) + | |
scale_x_continuous(expand = expansion(add = 10)) + | |
scale_y_continuous(expand = expansion(add = 10)) + | |
coord_fixed() + | |
theme_void() + | |
theme(plot.background = element_rect(fill = "#faf8e7", | |
color = NA)) | |
# v2 | |
poisson_disc(ncols = 100, nrows = 50, cell_size = 10) %>% | |
as_tibble() %>% | |
arrange(y) %>% | |
mutate(rando = runif(n()), | |
visibility = case_when( | |
y >= 300 ~ (500-y)/200, | |
y <= 200 ~ (y)/200, | |
TRUE ~ 1 | |
), | |
color = floor(x/100), | |
new_y = case_when( | |
y >= 300 ~ y + (1-visibility) * 50, | |
y <= 200 ~ y - (1-visibility) * 20, | |
TRUE ~ y | |
)) %>% | |
filter(visibility > rando) %>% | |
ggplot(aes(new_y, x, color = color)) + | |
geom_point(shape = 15, alpha = 0.8) + | |
scale_color_gradientn(colours = rainbow(20), guide = NULL) + | |
scale_x_continuous(expand = expansion(add = 10)) + | |
scale_y_continuous(expand = expansion(add = 10)) + | |
coord_fixed() + | |
theme_void() + | |
theme(plot.background = element_rect(fill = "#FFFFEE", | |
color = NA)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment