Skip to content

Instantly share code, notes, and snippets.

@ctesta01
Created February 15, 2022 14:42
Show Gist options
  • Select an option

  • Save ctesta01/a5dc011dcd3b97437f162f7184d37e3e to your computer and use it in GitHub Desktop.

Select an option

Save ctesta01/a5dc011dcd3b97437f162f7184d37e3e to your computer and use it in GitHub Desktop.
library(ggforce)
tw <- -2:1 + .5 # triangle width points
th <- 0:3 + .5 # triangle height points
triangle <- rbind(c(-2,0), c(2,0), c(0,4))
nudge_factor <- 0.15
df <- tibble::tribble(
~x, ~y, ~label,
tw[1]+nudge_factor, th[1], "cleaning\nhygeine",
tw[2], th[1], "fun\nexercise\nstretching",
tw[3], th[1], "nutrition\nhydration",
tw[4]-nudge_factor, th[1], "rest\nrelaxation",
mean(tw[c(1,2)])+nudge_factor, th[2], "intellectual\nstimulation",
mean(tw[c(2,3)]), th[2], "reflection\nmeditation",
mean(tw[c(3,4)])-nudge_factor, th[2], "socialization",
mean(tw[c(1:3)])+nudge_factor/1.5, th[3], "artful\nexpression",
mean(tw[c(2:4)])-nudge_factor/1.5, th[3], "financial\nmanagement",
0, th[4]-nudge_factor, "purpose\nmoral\nvirtue"
)
ggplot(df, aes(x = x, y = y, label = label, group = -1L)) +
geom_voronoi_tile(aes(fill = label), color = 'black', bound = triangle, alpha=0.7) +
geom_text(size = 3) +
labs(title = "A re-envisioning of Maslow's hierarchy of needs") +
theme_void() +
scale_color_manual(values = c(`b` = 'black', `a` = 'white')) +
scale_fill_viridis_d(option = 'inferno', begin = 0.2) +
theme(plot.title = element_text(size = 14, vjust = 1, hjust = 0.5)) + # Center ggplot title
theme(legend.position = 'none')
ggsave("riff_on_maslow.png", width = 6, height = 5)
ggsave("riff_on_maslow.jpg", width = 6, height = 5)
@ctesta01

Copy link
Copy Markdown
Author

the created plot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment