Skip to content

Instantly share code, notes, and snippets.

@jonspring
Created September 15, 2022 18:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jonspring/b07d484a8e9f263c819893da8916ea52 to your computer and use it in GitHub Desktop.
Save jonspring/b07d484a8e9f263c819893da8916ea52 to your computer and use it in GitHub Desktop.
# inspired by https://twitter.com/nytimes/status/1569377877774188551
# https://www.nytimes.com/2022/09/11/nyregion/hasidic-schools-nyc-officials.html
library(tidyverse);
library(particles); library(tidygraph); library(ggraph)
tibble(group = rep(c(1, 1.3), each = 300),
value = rbeta(600, 2-group, group^3),
radius = 0.01) -> a
ggplot(a, aes(value, group)) +
geom_jitter()
tbl_graph(a) %>%
simulate(setup = predefined_genesis(value, group, 0, 0)) %>%
wield(random_force, xmin = -0.01, xmax = 0.01, ymin = -0.01, ymax = 0.01) %>%
wield(y_force, y = group, strength = 0.1) %>%
wield(x_force, x = value, strength = 0.01) %>%
wield(collision_force, radius = radius*1.1, n_iter = 5, strength = 1) %>%
evolve(1000) %>%
as_tibble() -> a_result
ggplot(a_result) +
ggforce::geom_circle(aes(x0=x, y0=y, r=radius),
fill = "orange", color = NA) +
coord_equal() +
theme_minimal()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment