Discover millions of ebooks, audiobooks, and so much more with a free trial

Only $11.99/month after trial. Cancel anytime.

R Graph Essentials
R Graph Essentials
R Graph Essentials
Ebook319 pages1 hour

R Graph Essentials

Rating: 0 out of 5 stars

()

Read preview

About this ebook

R has undergone an explosion of popularity around the world. The wide range of graphs and options for creating high-impact visualizations makes R a highly effective tool for researchers, data analysts, students, and others.

This book starts with the basics of R and the principles of creating graphics, focusing on scatterplots and line graphs for research and data analysis.

After that you will learn how to include mathematical expressions on your graphs and create bar charts, histograms, boxplots, and so on using advanced functions. The book then dives deeper into shading and coloring your graphs and labeling points on graphs using the qplot function. After that you will learn how to use the ggplot package to control symbol color, size, shape, and many other attributes.

By the end of this book, you will have expert skills to create attractive and informative graphics and design professional-level graphs.

LanguageEnglish
Release dateSep 22, 2014
ISBN9781783554560
R Graph Essentials

Related to R Graph Essentials

Related ebooks

Programming For You

View More

Related articles

Reviews for R Graph Essentials

Rating: 0 out of 5 stars
0 ratings

0 ratings0 reviews

What did you think?

Tap to rate

Review must be at least 10 words

    Book preview

    R Graph Essentials - David Alexander Lillis

    Table of Contents

    R Graph Essentials

    Credits

    About the Author

    About the Reviewers

    www.PacktPub.com

    Support files, eBooks, discount offers, and more

    Why subscribe?

    Free access for Packt account holders

    Preface

    What this book covers

    What you need for this book

    Who this book is for

    Conventions

    Reader feedback

    Customer support

    Downloading the example code

    Downloading the color images of this book

    Errata

    Piracy

    Questions

    1. Base Graphics in R – One Step at a Time

    Learning basic graphics techniques

    Creating and joining points

    Creating scatterplots and line plots

    Colors in R

    Passing parameter values to titles and labels

    Including a regression line

    Graphing mathematical functions

    R provides many options

    Creating graphs with several curves

    Customizing your axes

    Creating axis labels

    Creating multiple graphs on the same page

    Saving your graphs

    Including mathematical expressions on your plots

    Summary

    2. Advanced Functions in Base Graphics

    Reading datasets into R

    Including a regression line and residuals

    A medical dataset to create graphs

    Creating complex multiple axes

    Superposing graphs

    Creating point labels

    Including a grid on your graph

    Shading and coloring your graph

    Using polygon() to shade under a normal curve

    Creating bar charts

    Including a legend

    Creating histograms

    Creating boxplots

    Creating pie charts

    Creating dotcharts

    R's color palettes

    Using smoothers on your graph

    Creating scatterplot matrices

    Writing functions to create graphs

    Including error bars on your graph

    Summary

    3. Mastering the qplot Function

    About qplot

    The qplot syntax

    Producing scatterplots using qplot

    Subsetting your data before graphing

    Mapping aesthetics to categorical variables

    Controlling colors on your graph

    Setting up graphs as objects

    Creating facet plots

    Creating line graphs using qplot

    Creating multiple curves simultaneously

    Including smoothed curves

    Creating histograms with qplot

    Creating facet plots for histograms

    Creating kernel density plots

    Creating bar charts

    Creating boxplots

    Creating graphs with dates

    Summary

    4. Creating Graphs with ggplot

    Getting started with ggplot

    Mapping color, shape, and size to a variable

    Modifying the plotting background

    Controlling the legend name and legend labels

    Modifying the x and y axes

    Creating attractive color schemes

    Creating curves for each factor level

    Creating histograms

    Creating bar charts

    Creating a stacked bar chart

    Creating a grouped bar chart

    Creating a faceted bar chart

    Creating boxplots

    Labeling points with text

    Mapping color to text

    Including regression lines

    Summary

    Index

    R Graph Essentials


    R Graph Essentials

    Copyright © 2014 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: September 2014

    Production reference: 1150914

    Published by Packt Publishing Ltd.

    Livery Place

    35 Livery Street

    Birmingham B3 2PB, UK.

    ISBN 978-1-78355-455-3

    www.packtpub.com

    Cover image by Arvind Shetty (<arvindshetty86@gmail.com>)

    Credits

    Author

    David Alexander Lillis

    Reviewers

    Mzabalazo Z. Ngwenya

    Donato Teutonico

    Tengfei Yin

    Commissioning Editor

    Pramila Balan

    Acquisition Editor

    Reshma Raman

    Content Development Editor

    Akashdeep Kundu

    Technical Editor

    Rohit Kumar Singh

    Copy Editors

    Roshni Banerjee

    Adithi Shetty

    Project Coordinator

    Kartik Vedam

    Proofreaders

    Simran Bhogal

    Maria Gould

    Ameesha Green

    Indexer

    Hemangini Bari

    Production Coordinator

    Arvindkumar Gupta

    Cover Work

    Arvindkumar Gupta

    About the Author

    David Alexander Lillis is an experienced researcher and statistician, having worked in research evaluation, agricultural and forestry statistics, and education research and statistics. Currently, David delivers lectures in mathematics, statistics, and research methods at the New Zealand Institute of Sport in New Zealand. He is the owner and Director of Sigma Statistics and Research Limited, a New Zealand-based consultancy specializing in training, software development, data analysis, and statistical modelling using R. David holds an Honor's degree and Master's degree in Physics and Mathematics, and a PhD from Curtin University in Perth, Australia.

    I wish to thank my family—Anna (my wife), David (my eight-year old son), and Coral (my mother) for their patience and support while I worked on this book. In addition, I wish to thank the three reviewers for their helpful feedback.

    About the Reviewers

    Mzabalazo Z. Ngwenya has worked extensively in the field of statistical consulting and currently works as a biometrician. He holds an MSc degree in Mathematical Statistics from the University of Cape Town, and is currently pursuing a PhD. His research interests include statistical computing, machine learning, and spatial statistics. Previously, he was involved in reviewing Learning RStudio for R Statistical Computing, Mark P.J. van der Loo and Edwin de Jonge, Packt Publishing; R Statistical Application Development by Example Beginner's Guide, Prabhanjan Narayanachar Tattar, Packt Publishing; and Machine Learning with R, Brett Lantz, Packt Publishing.

    Donato Teutonico has several years of experience in the modeling and simulation of drug effects and clinical trials in industrial and academic settings. He received his Pharm.D. degree from the University of Turin, Italy, specializing in Chemical and Pharmaceutical Technology, and his PhD in Pharmaceutical Sciences from Paris-Sud University, France.

    He is the author of two R packages for Pharmacometrics: CTS template and panels-for-pharmacometrics; both are available on Google code. He is also the author of Instant R Starter, Packt Publishing.

    Tengfei Yin earned his BS degree in Biological Science and Biotechnology from Nankai University in China and a PhD in Molecular, Cellular and Developmental Biology (MCDB) with a focus on computational biology and bioinformatics from Iowa State University. His research interests include information visualization, high-throughput biological data analysis, data mining, machine learning, and applied statistical genetics. He has developed and maintained several software packages in R and Bioconductor.

    www.PacktPub.com

    Support files, eBooks, discount offers, and more

    You might want to visit www.PacktPub.com for support files and downloads related to your book.

    Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.PacktPub.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at for more details.

    At www.PacktPub.com, you can also read a collection of free technical articles, sign up for a range of free newsletters and receive exclusive discounts and offers on Packt books and eBooks.

    http://PacktLib.PacktPub.com

    Do you need instant solutions to your IT questions? PacktLib is Packt's online digital book library. Here, you can access, read and search across Packt's entire library of books.

    Why subscribe?

    Fully searchable across every book published by Packt

    Copy and paste, print and bookmark content

    On demand and accessible via web browser

    Free access for Packt account holders

    If you have an account with Packt at www.PacktPub.com, you can use this to access PacktLib today and view nine entirely free books. Simply use your login credentials for immediate access.

    Preface

    Reading this book will enable you to learn very quickly how to create wonderful graphics using R. Since R is based on syntax, the time required to master R can be considerable. However, creating high quality and attractive graphics is made easy through the syntax and step-by-step explanations of this book. By reading this book, you will learn how to introduce attractive color schemes, create headings and legends, design your own axes and axes labels, create mathematical expressions on your graphs, and much more.

    What this book covers

    Chapter 1, Base Graphics in R – One Step at a Time, introduces the basic components of a graph (headings, symbols, lines, colors, axes, labels, legends, and so on) and outlines how to use the R syntax to create these components.

    Chapter 2, Advanced Functions in Base Graphics, covers the techniques required to create professional-level graphs in R, including bar charts, histograms, boxplots, pie charts, and dotcharts. It also covers regression lines, smoothers, and error bars.

    Chapter 3, Mastering the qplot Function, explains how to use qplot to create a wide range of basic but attractive graphs.

    Chapter 4, Creating Graphs with ggplot, introduces you to ggplot,

    Enjoying the preview?
    Page 1 of 1