R gist — Dot matrix charts with ggplot2

Gist
Author

Stefano Coretta

Published

November 21, 2021

Set up

Create data

dots <- tibble(
  group = as.character(unlist(mapply(rep, c("a", "b", "c"), c(26, 11, 7)))),
  x = rep(1:10, length.out = length(group)),
  y = rep(1:(ceiling(length(group) / 10)), each = 10)[1:length(group)]
)

Plot dot matrix chart

dots %>%
  ggplot(aes(x, -y, colour = group)) +
  geom_point(size = 10) +
  scale_color_brewer(type = "qual") +
  theme_minimal() +
  theme(
    panel.grid = element_blank(),
    axis.title = element_blank(),
    axis.text = element_blank(),
    legend.position = "bottom"
  )

To do

  • Order groups by descending count.
  • Reduce spacing.