Data visualization from a category theory perspective - Barreira, Davi Sales (2025)
In the field of data visualization, there is a persistent challenge in balancing expressiveness and abstraction across different tools and libraries. While some like D3 are highly expressive but lack abstraction, others like Seaborn are highly abstracted but not very expressive. Visualization grammars have emerged as a solution to this trade-off, attempting to balance abstraction and expressiveness through structured rules and consistent principles. While successful in some respects, these grammars often fall short when handling more complex visualizations such as those involving nested or integrated graphics and custom graphical marks. To address these limitations, we propose a new theoretical framework that formalizes graphic specification and assembly through a constructive perspective, enhancing expressiveness without compromising abstraction. This approach treats data visualizations as diagrams, integrating diagramming and visualization into a unified framework. In order to formalize our proposal, we make use of Category Theory (CT). Category Theory excels at modeling compositional structures, which allows us to describe how visual components can be combined and transformed. Moreover, the deep connection between Category Theory and Functional Programming (FP) allows us to translate theoretical concepts into code, through a concept known as Categorical Programming. To validate the efficacy of our theoretical framework, we introduce a proof-of-concept implementation in the form of a visualization package named Vizagrams. Vizagrams operates as an embedded domain-specific language (DSL), implementing a visualization grammar over a diagramming DSL. We demonstrate its expressiveness through a gallery of visualizations, and evaluate its abstraction by comparing its graphic specifications against other grammars.