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

Visualizing distributions as count frequencies or probability densities


Histograms can represent the distribution of values either as frequency (the absolute number of times values fall within specific ranges) or as probability density (the proportion of the values that falls within specific ranges). In this recipe, we will learn how to choose one or the other.

Getting ready

We are only using base graphics functions for this recipe. So, just open up the R prompt and type in the following code. We will use the airpollution.csv example dataset for this recipe. So, let's first load it:

air<-read.csv("airpollution.csv")

How to do it...

We will use the hist() base graphics function to make our histogram, first showing the frequency and then probability density of nitrogen oxide concentrations:

hist(air$Nitrogen.Oxides,
xlab="Nitrogen Oxide Concentrations",
main="Distribution of Nitrogen Oxide Concentrations")

Now, let's make the same histogram but with probability instead of frequency:

hist(air$Nitrogen...