Book Image

Applied Data Visualization with R and ggplot2

By : Dr. Tania Moulik
Book Image

Applied Data Visualization with R and ggplot2

By: Dr. Tania Moulik

Overview of this book

Applied Data Visualization with R and ggplot2 introduces you to the world of data visualization by taking you through the basic features of ggplot2. To start with, you’ll learn how to set up the R environment, followed by getting insights into the grammar of graphics and geometric objects before you explore the plotting techniques. You’ll discover what layers, scales, coordinates, and themes are, and study how you can use them to transform your data into aesthetical graphs. Once you’ve grasped the basics, you’ll move on to studying simple plots such as histograms and advanced plots such as superimposing and density plots. You’ll also get to grips with plotting trends, correlations, and statistical summaries. By the end of this book, you’ll have created data visualizations that will impress your clients.
Table of Contents (10 chapters)

More on the Grammar of Graphics


The Grammar of Graphics is the language used to describe the various components of a graphic that represent data in a visualization. In this topic, you will learn more about the Grammar of Graphics and will use it to make plots. You wille-encounter some of the Grammar of Graphics terms used in the previous chapter.

We will now break down the Grammar of Graphics language, in order to understand the terms in greater detail. 

Layers

In ggplot2, every plot is built up as a layer. Layers are made up of geometric objects (geoms), their statistical transformations (stats), and their thematic aspects. Hence, each plot can be thought of as a separate variable, in and of itself. Aesthetic mappings, defined withaes(), describe how variables are mapped to visual properties, or  aesthetics. The following diagram depicts the use of the df and aes functions:

Let's look at an example. We will use the gapminder dataset. You can see the available variables in the following snippet...