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)

Advanced Plotting Techniques


Two of the most common advanced plotting techniques are scatter plots and bubble charts. Scatter plots show the relationship between two variables. A bubble chart can include a third variable. Each point (with its values (v1, v2, v3) of associated data) is plotted as a disk, where two of the values show the x and y locations, and the third depicts the size. Just like in a scatter plot, a bubble chart uses numerical variables for its x and y axes. You cannot use categorical variables in a bubble chart.

In this plot, we will plot the electricity consumption per capita for different years and different countries. The size of the point will vary, according to the population of the country.

Creating a Bubble Chart

In this section, we'll create a bubble chart showing the relationship between electricity consumption in different years for different countries. Let's begin by implementing the following steps:

  1. Make a subset of the dataset.
  2. Use geom_point to make a scatter plot...