R gist — Dot matrix charts with ggplot2

Gist
Author

Stefano Coretta

Published

November 21, 2021

1 Set up

2 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)]
)

3 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"
  )

4 To do

  • Order groups by descending count.
  • Reduce spacing.

Citation

BibTeX citation:
@online{coretta2021,
  author = {Coretta, Stefano},
  title = {R Gist — {Dot} Matrix Charts with Ggplot2},
  date = {2021-11-21},
  url = {https://stefanocoretta.github.io/posts/2021-11-21-dot-matrix-charts/},
  langid = {en}
}
For attribution, please cite this work as:
Coretta, Stefano. 2021. R gist — Dot matrix charts with ggplot2. https://stefanocoretta.github.io/posts/2021-11-21-dot-matrix-charts/.