Skip to content

Instantly share code, notes, and snippets.

@ryantimpe
Last active August 13, 2021 17:54
Show Gist options
  • Save ryantimpe/db731c2d786d8e1d12436d2c180d66fa to your computer and use it in GitHub Desktop.
Save ryantimpe/db731c2d786d8e1d12436d2c180d66fa to your computer and use it in GitHub Desktop.
#RecreationThursday 2021-08-12
#Recreation Thursday
# August 12, 2021
library(tidyverse)
library(ggforce)
library(scales)
n_x = 13 #Number of circles along bottom X
n_y = 19 #Number of circles along side Y
#Create a custom y axis ----
# Soooo much trial and error.
# I think a cubic function is too steep
riley_fun = function(x){
linear_scale = 30.25*2
mid_point = 11.5
#These decimal values are from looking at the distortions with diff() and adjusting
case_when(x < 6 ~ (x-mid_point)*linear_scale + 166.375,
x > 15 ~ (x-mid_point)*linear_scale - 168.875,
TRUE ~(x-mid_point)^3)
}
riley_axis_trans = function(){scales::trans_new("riley_axis",
function(x) riley_fun(x),
function(x) riley_fun(x))}
# 1-increment cirles
expand_grid(x = 1:n_x,
y = 1:n_y) %>%
# Between-increment circles
bind_rows(expand_grid(
x = (1+1/2):(n_x-1/2),
y = (1+1/2):(n_y-1/2),
)) %>%
#Some gentle trial and error for the shading
#... thanks to my years playing with {rayshader} and datasaurs
mutate(shade = sin((x-y - 5)/3)) %>%
ggplot() +
ggforce::geom_circle(aes(x0=x, y0=y, r=0.3,
alpha = shade),
color = NA, fill = "#333333",
inherit.aes = FALSE) +
coord_trans(x="identity", y="riley_axis") +
labs(caption = "#RecreationThursday | @ryantimpe") +
theme_void() +
theme(legend.position = "none",
plot.background = element_rect(fill = "#d4d1ce"))
#Recreation Thursday - Remix
# August 12, 2021
library(tidyverse)
library(ggforce)
library(scales)
n_x = 19 #Number of circles along bottom X
n_y = 19 #Number of circles along side Y
mid_point = 11.5
riley_axis2_trans = function(){scales::trans_new("riley_axis2",
function(x) (x-mid_point)^3,
function(x) (x-mid_point)^3)}
# 1-increment cirles
expand_grid(x = 0:(n_x+1),
y = 0:(n_y+1)) %>%
# Between-increment circles
bind_rows(expand_grid(
x = (0+1/2):(n_x+1/2),
y = (0+1/2):(n_y+1/2),
)) %>%
#Some gentle trial and error for the shading
#... thanks to my years playing with {rayshader} and datasaurs
mutate(shade = sin(sqrt(abs(x^2-y^2)))) %>%
mutate(diag = x-y,
diag2 = x+y) %>%
ggplot() +
geom_path(aes(x-1/4, y+1/4, group = diag),
linetype = "dotted",
size = 0.5, alpha = 0.8,
color = "#fff8b4") +
geom_path(aes(x, y+1/2, group = diag2),
linetype = "dotted",
size = 0.5, alpha = 0.8,
color = "#fff8b4") +
ggforce::geom_circle(aes(x0=x, y0=y, r=0.25,
alpha = shade),
color = NA, fill = "white",
inherit.aes = FALSE) +
coord_trans(x="riley_axis2", y="riley_axis2",
xlim = c(0.5, n_x+0.5), ylim = c(.5, n_y+0.5), expand = 0) +
# coord_fixed() +
labs(caption = "#RecreationThursday | @ryantimpe") +
theme_void() +
theme(legend.position = "none",
plot.background = element_rect(fill = "#090935"),
plot.caption = element_text(color = "#fff8b4"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment