Skip to content

Instantly share code, notes, and snippets.

@gkaramanis
Last active December 12, 2024 17:28
Show Gist options
  • Save gkaramanis/315126ddb74cef875455432ff420a46d to your computer and use it in GitHub Desktop.
Save gkaramanis/315126ddb74cef875455432ff420a46d to your computer and use it in GitHub Desktop.
library(tidyverse)
library(ggforce)
bl_gradient <- grid::linearGradient(colours = rev(c("gray40", "#9B9B9B")),
stops = c(0.12, 0.4, 0.6))
br_gradient <- grid::linearGradient(colours = rev(c("grey10", "#484848")),
x1 = unit(0, "npc"), y1 = unit(0, "npc"),
x2 = unit(1, "npc"), y2 = unit(1, "npc"),
stops = c(0, 0.5, 0.8))
bb_gradient <- grid::linearGradient(colours = rev(c("grey30", "#D7D7D7")),
x1 = unit(0.5, "npc"), y1 = unit(0, "npc"),
x2 = unit(0.5, "npc"), y2 = unit(1, "npc"),
stops = c(0.2, 0.5)
)
cube <- tribble(
~face, ~x, ~y, ~fill,
"bl", c(-2, -2, 0, 0), c(-1.15, 1.15, 2.3, -2.3), bl_gradient,
"br", c(0, 2, 2, 0), c(2.3, 1.15, -1.15, -2.3), br_gradient,
"bb", c(-2, 0, 2, 0), c(-1.15, -2.3, -1.15, 0), bb_gradient,
"ft", c(-2, 2, 0), c(1.15, 1.15, 0), "white",
"fr", c(0, 2, 0), c(0, 1.15, -2.3), "#E3E3E3"
) %>%
unnest_longer(c(x, y)) %>%
mutate(
face = fct_inorder(face),
x = x * 0.9,
y = y * 0.9
)
ggplot() +
geom_ellipse(aes(x0 = 0, y0 = 0, a = 3, b = 3, m1 = 4.5, angle = 0), fill = "black") +
geom_polygon(data = cube, aes(x, y, group = face, fill = fill)) +
scale_fill_identity() +
coord_fixed() +
theme_void() +
theme(
plot.background = element_rect(fill = "grey99", color = NA)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment