Grammar of Graphics

Karl Ho

School of Economic, Political and Policy Sciences

University of Texas at Dallas

Data Visualization

Grammar of Graphics

Leland Wilkinson's concepts and theories of graphics

  • Based on language and semantic structure of writing
  • Build on human understanding of languages
  • How to write --> How to compose graphics
  • Applications

Wilkinson

A grammar is a formal system of rules for generating lawful statements in a language.

The grammar of graphics goes beyond a limited set of charts (words) to an  unlimited world of graphical forms (statements). 

The rules of graphics grammar are sometimes mathematical and sometimes aesthetic.

Wilkinson

Mathematics provides symbolic tools for representing abstractions. 

Aesthetics, in the original Greek sense, offers principles for relating sensory attributes (color, shape, sound, etc.) to abstractions.. 

GG focuses on rules for constructing graphs mathematically and then representing them as graphics aesthetically.

Wilkinson

Grammar gives language rules. 

The word stems from the Greek noun for letter or mark \(\gamma\rho\acute{\alpha}\mu\mu\alpha\).

That derives from the Greek verb for writing \(\gamma\rho\acute{\alpha}\phi\omega\), which is the source of our English word graph.

Wilkinson

Programming a computer to draw graphs teaches most surely the ancient lesson that God is in the detail.

- Wilkinson, p. 2

Grammar of Graphics (gg)

  • A grammar of graphics facilitates coordinated activity in a set of relatively autonomous components.

  • This grammar enables us to develop a system in which adding a graphic to a frame (say, a surface) requires no adjustments or changes in definitions other than the simple message “add this graphic.”

  • Similarly, we can remove graphics, transform scales, permute attributes, and make other alterations without redefining the basic structure.

Object-Oriented Design (OOD)

  • Objects are basic components of systems.

    • data, line (vector), axes

  • Objects are often reusable.

  • Objects can inherit attributes and behavior from other objects (communicative).

  • Objects are often polymorphous, different objects can be induced to respond to the same message in different ways.  

  • Objects facilitate abstraction.

Why Object-Oriented Design?

A graph is a set of points. A graphic is a physical representation of a graph, accomplished by realizing graphs with aesthetic attributes such as size or color.


An object-oriented graphics system requires explicit definitions for these realizations and rules for relating them to data and for organizing their behavior in a computational environment.

From the OOD perspective, graphics are collections of objects. If the messages between these objects follow a simple grammar, then they will behave consistently and flexibly. To introduce this idea, we will focus on three stages of graphic creation:

  1. Specification

  2. Assembly

  3. Display

Why Object-Oriented Design?

Three stages of graphic creation

  1. Specification

    •  Translation of user actions into a formal language
    •  Required for an automatic system to understand the graphic request

  2. Assembly
    •  Assemble a graphical scene from a specification; coordinate
    its geometry, layout, and aesthetics

  3. Display
    •  Aesthetic aPributes
    •  Dynamic design to enable brushing, drill-down, zooming, linking, etc.

Specification involves the translation of user actions into a formal language (so the graphics can be programmed and replicated).  Another way of defining specification is to say that it is the deep grammar of a graphic, which has a highly organized and constrained set of rules. 

Specification

Statistical graphic specifications are expressed in six statements:

  1. DATA: a set of data operations that create variables from datasets

  2. TRANS: variable transformations (e.g., rank)

  3. SCALE: scale transformations (e.g., log)

  4. COORD: a coordinate system (e.g., polar)

  5. ELEMENT: graphs (e.g., points) and their aesthetic attributes (e.g., color)

  6. GUIDE: one or more guides (axes, legends, etc.).

Specification

A statistical graphics computer program must be able to assemble a graphical scene from a specification in the same manner as a drawing or modeling program puts together a realistic scene from specification components.

Assembly

How we build a scene from a specification affects how the result behaves. A scene can be dynamic or static, linked to external data or isolated, modifiable or immutable, depending on how we assemble it.

A graph must be rendered using aesthetic attributes and a display system (e.g., paper, video, hologram).

  • Production graphics require little in this area other than basic drawing capabilities.

  • Dynamic graphics and scientific visualization,  require sophisticated designs to enable brushing, drill-down, zooming, linking, and other operations relating data to graphics.

Display

Object-Oriented Design (OOD)

Components or layers

Object-Oriented Design (OOD)

Components or layers

Language of Graphics

A scatterplot is a point graphic embedded in a frame. 

A bar chart is an interval graphic bound to an aggregation function embedded in a frame.

 A pie chart is a polar, stacked, interval graphic mapped on proportions. 

A radar chart is a line graphic in polar parallel coordinates. 

A SPLOM (scatterplot matrix) is a crossing of nested scatterplots in rectangular coordinates. 

A trellis display is a graphic faceted on crossed categorical variables in a rectangular coordinate system.

Wickham

A grammar of graphics is a tool that enables  concise description of the components of a graphic.

Such a grammar allows moving beyond named graphics and gain insight into the deep structure that underlies statistical graphics.

 

Data Visualization: Grammar of Graphics

By Karl Ho

Data Visualization: Grammar of Graphics

  • 235