Book Image

R Graphs Cookbook Second Edition

Book Image

R Graphs Cookbook Second Edition

Overview of this book

Table of Contents (22 chapters)
R Graphs Cookbook
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

Introduction


In this chapter, we will mainly use the ggplot2 library to visualize data with common graphs, such as bar charts, histograms, boxplots, and scatter plots. The ggplot2 library has the implementation of Grammar of Graphics, which gives the user the flexibility to produce any kind of graph by introducing layered facilities. At the end of this chapter, we will see how we can easily annotate the graphs using the theme option of the ggplot2 library.

Throughout this chapter, we will use a single dataset. We will simulate the dataset with some numeric and categorical variables so that we can use the same dataset for each recipe.

There are four numeric variables, namely disA, disB, disC, and disD. Here, disA and disD are correlated in the sense that disD is produced with the same values of disA but with an added random error from the normal distribution with a mean of zero and a standard deviation of three. There are three categorical variables that represent the age category, sex, and...