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

Creating a normal Q-Q plot


Commonly, we compare an empirical distribution with known theoretical distribution. The most popular and most used theoretical distribution is the normal distribution. To compare an empirical distribution with a normal distribution, we use a normal Q-Q plot. In this recipe, we will see how we can compare a distribution of a numeric variable with the theoretical normal distribution through a normal Q-Q plot.

Getting ready

The data for this recipe is generated using the following code:

# Set a seed value to make the data reproducible
set.seed(12345)
qqdata <-data.frame(disA=rnorm(n=100,mean=20,sd=3),
                disB=rnorm(n=100,mean=25,sd=4),
                disC=rnorm(n=100,mean=15,sd=1.5),
                age=sample((c(1,2,3,4)),size=100,replace=T),
                sex=sample(c("Male","Female"),size=100,replace=T),
                econ_status=sample(c("Poor","Middle","Rich"),
                size=100,replace=T))

How to do it…

We can produce the plot with the...