R Graphs Cookbook
Detailed hands-on recipes for creating the most useful
types of graphs in R—starting from the simplest versions
to more advanced applications
Hrishi V. Mittal
BIRMINGHAM - MUMBAI
R Graphs Cookbook
Copyright © 2011 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or
transmitted in any form or by any means, without the prior written permission of the publisher,
except in the case of brief quotations embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of the
information presented. However, the information contained in this book is sold without
warranty, either express or implied. Neither the author, nor Packt Publishing, and its dealers
and distributors will be held liable for any damages caused or alleged to be caused directly or
indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the companies
and products mentioned in this book by the appropriate use of capitals. However, Packt
Publishing cannot guarantee the accuracy of this information.
First published: January 2011
Production Reference: 1110111
Published by Packt Publishing Ltd.
32 Lincoln Road
Olton
Birmingham, B27 6PA, UK.
ISBN 978-1-849513-06-7
www.packtpub.com
Cover Image by Charwak (charwak86@gmail.com)
Credits
Author
Hrishi V. Mittal
Reviewers
Patrick Burns
Paul Butler
Markus Loecher
Paolo Sonego
Acquisition Editor
Eleanor Duffy
Development Editor
Maitreya Bhakal
Technical Editor
Vanjeet D'souza
Copy Editor
Neha Shetty
Editorial Team Leader
Akshara Aware
Project Team Leader
Priya Mukherji
Project Coordinator
Jovita Pinto
Proofreader
Joanna McMahon
Indexer
Tejal Daruwale
Production Coordinator
Melwyn D'sa
Aparna Bhagat
Cover Work
Melwyn D'sa
About the Author
Hrishi V. Mittal has been working with R for a few years in different capacities. He was
introduced to the exciting world of data analysis with R when he was working as a Senior
Air Quality Scientist at King's College London, where he used R extensively to analyze
large amounts of air pollution and trafc data to inform the Mayor of London's Air Quality
Strategy. He has experience in various other programming languages, but prefers R for data
analysis and visualization. He is actively involved in various R mailing lists, forums and the
development of some R packages.
In early 2010, Hrishi started Pretty Graph Limited (
www.prettygraph.com), a software
company specializing in web-based data visualization products. The company's agship
product, Pretty Graph, uses R as the backend engine for helping researchers and businesses
visualize and analyze data. The goal is to bring the power of R to a wider audience by providing
a modern graphical user interface which can be accessed by anyone and from anywhere
simply by using a web browser.
First and foremost, I am grateful to the creators of R, Ross Ihaka and Robert
Gentleman, and the countless other contributors who have made one of the
greatest open source software of all time.
I would like to thank my wife Louise for her patience and support throughout
the writing of the book. Her feedback on the writing itself has also been
very useful. Special thanks are also due to Clive and Jimmy, who have
consistently provided silent, warm and furry stress relief.
I'm grateful to my parents and sister for their love and the pride they always
take in my work, even when they are not quite sure what I'm doing.
It's been nice to have support from my friends Madhavi Bhargava, Rohit
Menon and Aniruddha Kembavi, who have been very encouraging and at
times more excited than me about the book.
I'd also like to thank the reviewers for pointing out some errors and
suggesting valuable improvements. Last, but not least, I'd like to thank my
editor Eleanor Duffy and the rest of the team at Packt, who have been very
professional, understanding and helpful throughout the project.