Search icon
Subscription
0
Cart icon
Close icon
You have no products in your basket yet
Save more on your purchases!
Savings automatically calculated. No voucher code required
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
R Graph Essentials

You're reading from  R Graph Essentials

Product type Book
Published in Sep 2014
Publisher
ISBN-13 9781783554553
Pages 190 pages
Edition 1st Edition
Languages

Table of Contents (11) Chapters

R Graph Essentials
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
1. Base Graphics in R – One Step at a Time 2. Advanced Functions in Base Graphics 3. Mastering the qplot Function 4. Creating Graphs with ggplot Index

Creating histograms with qplot


Now, let's learn how to create a histogram using geom = "histogram" and control the bin width using the argument binwidth. In this example, we will create a histogram of the heights of the patients and select a bin width of 10 cm. The syntax is as follows:

qplot(HEIGHT, geom = "histogram",  ylab = "COUNT", xlab = "HEIGHT", binwidth = 10)

Here is our histogram:

Our histogram has a rather chunky appearance, and we may wish to change the color and other attributes of the default histogram. By the way, note what happens if we use the syntax color = I("blue"):

qplot(HEIGHT, geom = "histogram",  ylab = "COUNT", xlab = "HEIGHT", binwidth = 10, color = I("blue"), fill = I("wheat"))

Now the histogram looks like this:

We get blue outlines for the bars and the axes. Remember that, for histograms, the color argument controls the color of the histogram outlines, while the argument fill controls the color of the bars.

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime}