Why you need grammar of graphics — part 3 of “R for Applied Economics” guide

Dima Diachkov
3 min readJan 27, 2023

--

What is the grammar of graphics?

The grammar of graphics is a way of thinking about how to create graphical representations of data. It is based on the idea that a graph can be broken down into a set of components, such as data, scales, and layers. By understanding these components, it is possible to create a wide range of different types of plots, from basic scatter plots to complex multivariate visualizations.

For example, a scatter plot can be thought of as a combination of data (x and y coordinates of each point), scales (x and y axes), and a layer (the points themselves). By understanding these components, it is possible to create different types of scatter plots, such as a scatter plot with different point shapes or colors.

The “bible” in this field is groundbreaking “The Grammar of Graphics (Statistics and Computing)” by Leland Wilkinson. You can find it on Amazon for 40–150$ (price varies for Kindle, paperback, or hardcover edition), and it is worth the money.

“The Grammar of Graphics (Statistics and Computing)” by Leland Wilkinson

What are the main features of grammar of graphics?

One of the main features of the grammar of graphics is its flexibility. It allows for the creation of a wide range of plots, including scatter plots, line plots, bar plots, and more. Additionally, it allows for the creation of multiple layers in a single plot, which can be used to add additional information to the plot.

Another feature of the grammar of graphics is its modularity. Each component of a plot can be created and manipulated independently, making it easy to change the appearance of a plot without having to start from scratch.

Why is it different from ordinary charts?

The grammar of graphics is different from ordinary charts in that it provides a structure for creating and understanding graphical representations of data. It is based on the idea that a graph can be broken down into a set of components, such as data, scales, and layers. This allows for greater flexibility and control over the appearance of a plot and allows for the creation of more complex visualizations.

I told you in part 2 — the grammar of graphics is all about the layers!

Credits: ScienceCraft

How can it be used for powerful visualization in R?

The grammar of graphics can be used for powerful visualization in R by using packages such as ggplot2. This package follows the guidelines of the grammar of graphics and provides a wide range of tools for creating and manipulating plots. By using ggplot2, it is possible to create a wide range of different types of plots, from basic scatter plots to complex multivariate visualizations.

Which packages are following the guidelines?

One of the most popular packages for following the guidelines of the grammar of graphics is ggplot2. This package is widely used in R for creating and manipulating plots and provides a wide range of tools for creating and manipulating plots. Other packages such as lattice, and ggvis also follow the grammar of graphics approach.

Conclusion

In conclusion, the grammar of graphics is a powerful concept that provides a structure for creating and understanding graphical representations of data. It allows for greater flexibility and control over the appearance of a plot and allows for the creation of more complex visualizations. By using packages such as ggplot2, it is possible to create a wide range of different types of plots in R, making it a powerful tool for data visualization.

Please clap 👏 and subscribe if you want to support me. Thanks!❤️‍🔥

--

--

Dima Diachkov

Balancing passion with reason. In pursuit of better decision making in economic analysis and finance with data science via R+Python