Overview of this book

R Graph Essentials
Credits
www.PacktPub.com
Preface
Free Chapter
Base Graphics in R – One Step at a Time
Advanced Functions in Base Graphics
Creating Graphs with ggplot
Index

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, which is an even more powerful graphics tool than qplot. We focus on the main techniques to modify your plotting background, titles, grid lines, legends, axes, labels, and colors. It also covers the essential methods to create plots using ggplot. You will learn how to create all the graph types that were covered in Chapter 1, Base Graphics in R – One Step at a Time, and Chapter 2, Advanced Functions in Base Graphics, but this time using the many special and attractive features of ggplot.

What you need for this book

To make the most of this book, you need to install R. Go to http://cran.r-project.org/ and click on the relevant download link for either Linux, Mac, or Windows. You will also need to install a plotting package called ggplot2. You can do so within R by entering the following syntax on the command line:

```install.packages("ggplot2")
```

Who this book is for

If you are a senior undergraduate or postgraduate student, professional researcher, statistician, or analyst, this is the book for you. It is preferable for you to have some prior experience in R. However, even if you are new to R, you can pick up enough from this book to create publication-quality graphs.

Conventions

In this book, you will find a number of styles of text that distinguish between different kinds of information. Here are some examples of these styles, and an explanation of their meaning.

Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: "The `legend()` command is very powerful and provides many options to create and place legends."

Any command-line input or output is written as follows:

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

New terms and important words are shown in bold. Words that you see on the screen, in menus or dialog boxes for example, appear in the text like this: "Note the use of the assigns operator, which consists of the less than sign followed by a minus sign."

Note

Warnings or important notes appear in a box like this.

Tip

Tips and tricks appear like this.

Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or may have disliked. Reader feedback is important for us to develop titles that you really get the most out of.

To send us general feedback, simply send an e-mail to , and mention the book title via the subject of your message.

If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide on www.packtpub.com/authors.

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

You can download the example code files for all Packt books you have purchased from your account at http://www.packtpub.com. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.

We also provide you a PDF file that has color images of the screenshots/diagrams used in this book. The color images will help you better understand the changes in the output. You can download this file from: https://www.packtpub.com/sites/default/files/downloads/4553OS_ColorGraphics.pdf.

Errata

Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you would report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the errata submission form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded on our website, or added to any list of existing errata, under the Errata section of that title. Any existing errata can be viewed by selecting your title from http://www.packtpub.com/support.

Piracy

Piracy of copyright material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works, in any form, on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.