library(ggplot2)
library(dplyr)
# Manually adjust position of N points,
# arranging them per the sunflower algorithm and then dodging groups
N <- 300
dat <- data.frame(
x = sample(1:2, size = N, replace = TRUE),
y = sample(1:7, size = N, replace = TRUE),
type = factor(sample(LETTERS[1:2], N, replace = TRUE))
) |>
group_by(x, y, type) |>
mutate(
x = sunflower(x = x, density = 1, aspect_ratio = 1),
y = sunflower(y = y, density = 1, aspect_ratio = 1),
x = if_else(type == "A", x - (1 / 8), x + (1 / 8))
)
ggplot(dat, aes(x, y, color = type, shape = type)) +
geom_point() + coord_equal()
Run the code above in your browser using DataLab