Search icon CANCEL
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 multiple curves simultaneously


Now let's learn how to create several curves in one graph, provided that the data is arranged correctly. Read the Children dataset from the code file of this chapter. It gives the heights and ages of four children. We want to produce a graph of Height against Age for each child, including both points and lines. Enter the following command:

attach(cheight)

Let's see the first eight rows of this dataset:

head(cheight, 8)

We get the following output:

  Child  Age Height
1  John  13    165
2  John  14    172
3  John  15    174
4  John  16    177
5  John  17    179
6  John  18    181
7  Mary  13    145
8  Mary  14    153

Note that the data is arranged in columns so that several measurements for each child appear in a single column. This format is ideal for creating multiple curves simultaneously. Before we start, let's remind ourselves of the names of each child. Since Child is a categorical variable, we can see each name using the levels() command:

levels...
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 €14.99/month. Cancel anytime}