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

Setting up graphs as objects


We can set up the initial graphing syntax as an object. In the next example, we call this object Y. We can use any object name, as long as it starts with an alphabetic character. We map the symbol color to ETH, a categorical variable of three levels. Then, we impose our own colors by adding the new colors as a layer to the object Y:

Y <- qplot(HEIGHT, WEIGHT_1, data = T, main = "HEIGHT vs. WEIGHT", xlab = "HEIGHT (cm)", ylab = "WEIGHT BEFORE TREATMENT (kg)" , geom = "point" , color = factor(ETH), size = 2, alpha = I(0.7))   

Y + scale_color_manual(values = c("darkgreen","red", "yellow"))

The output is as follows:

Setting up graphs as objects can be very useful. Using your initial object, you can try out different color schemes, symbol types, and other attributes until you get the appearance you want.

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}