Graphing Data with R
An Introduction
Publisher: O'Reilly Media
Release Date: October 2015
Pages: 258
Read on O'Reilly Online Learning with a 10day trial
Start your free trial now Buy on AmazonWhere’s the cart? Now you can get everything with O'Reilly Online Learning. To purchase books, visit Amazon or your favorite retailer. Questions? See our FAQ or contact customer service:
18008898969 / 7078277019
support@oreilly.com
It’s much easier to grasp complex data relationships with a graph than by scanning numbers in a spreadsheet. This introductory guide shows you how to use the R language to create a variety of useful graphs for visualizing and analyzing complex data for science, business, media, and many other fields. You’ll learn methods for highlighting important relationships and trends, reducing data to simpler forms, and emphasizing key numbers at a glance.
Anyone who wants to analyze data will find something useful here—even if you don’t have a background in mathematics, statistics, or computer programming. If you want to examine data related to your work, this book is the ideal way to start.
 Get started with R by learning basic commands
 Build single variable graphs, such as dot and pie charts, box plots, and histograms
 Explore the relationship between two quantitative variables with scatter plots, highdensity plots, and other techniques
 Use scatterplot matrices, 3D plots, clustering, heat maps, and other graphs to visualize relationships among three or more variables
Table of Contents

Getting Started with R

Chapter 1 R Basics
 Downloading the Software
 Try Some Simple Tasks
 User Interface
 Installing a Package: A GUI Interface
 Data Structures
 Sample Datasets
 The Working Directory
 Putting Data into R
 Sourcing a Script
 UserWritten Functions
 A Taste of Things to Come

Chapter 2 An Overview of R Graphics
 Exporting a Graph
 Exploratory Graphs and Presentation Graphs
 Graphics Systems in R


SingleVariable Graphs

Chapter 3 Strip Charts
 A Simple Graph
 Data Can Be Beautiful

Chapter 4 Dot Charts
 Basic Dot Chart
 Exercise 41

Chapter 5 Box Plots
 The Box Plot
 Nimrod Again
 Making the Data Beautiful

Chapter 6 StemandLeaf Plots
 Basic StemandLeaf Plot
 Exercise 61

Chapter 7 Histograms
 Simple Histograms
 Histograms with a Second Variable

Chapter 8 Kernel Density Plots
 Density Estimation
 The Cumulative Distribution Function

Chapter 9 Bar Plots (Bar Charts)
 Basic Bar Plot
 Spine Plot
 Bar Spacing and Orientation

Chapter 10 Pie Charts
 Ordinary Pie Chart
 Fan Plot

Chapter 11 Rug Plots
 The Rug Plot
 Exercise 111


TwoVariable Graphs

Chapter 12 Scatter Plots and Line Charts
 Basic Scatter Plots
 Line Charts
 Templates
 Enhanced Scatter Plots

Chapter 13 HighDensity Plots
 Working with Large Datasets

Chapter 14 The BlandAltman Plot
 Assessing Measurement Reliability

Chapter 15 QQ Plots
 Comparing Sets of Numbers


Multivariable Graphs

Chapter 16 Scatter plot Matrices and Corrgrams
 Scatter plot Matrix
 Corrgram
 Generalized Pairs Matrix with Mixed Quantitative and Categorical Variables

Chapter 17 ThreeDimensional Plots
 3D Scatter plots
 False Color Plots
 Bubble Plots

Chapter 18 Coplots (Conditioning Plots)
 The Coplot
 Exercise 181

Chapter 19 Clustering: Dendrograms and Heat Maps
 Clustering
 Heat Maps

Chapter 20 Mosaic Plots
 Graphing Categorical Data


What Now?

Chapter 21 Resources for Extending Your Knowledge of Things Graphical and R Fluency
 R Graphics
 General Principles of Graphics
 Learning More About R
 Statistics with R

Appendix References

Appendix R Colors

Appendix The R Commander Graphical User Interface

Appendix Packages Used/Referenced

Appendix Importing Data from Outside of R
 Some Useful Internet Data Repositories
 Importing Data of Various Types into R

Appendix Solutions to Chapter Exercises
 Exercises 11 Through 14
 Exercise 31
 Exercise 32
 Exercise 41
 Exercise 42
 Exercise 51
 Exercise 52
 Exercise 61
 Exercise 62
 Exercise 71
 Exercise 81
 Exercise 82
 Exercise 91
 Exercise 92
 Exercise 101
 Exercise 102
 Exercise 111
 Exercise 121
 Exercise 122
 Exercise 131
 Exercise 141
 Exercise 151
 Exercise 152
 Exercise 161
 Exercise 171
 Exercise 172
 Exercise 181
 Exercise 191
 Exercise 192
 Exercise 193
 Exercise 201
 Exercise 211

Appendix Troubleshooting: Why Doesn’t My Code Work?
 Misspelling
 Confusing Uppercase/Lowercase
 Too Few (or Too Many) Parenthesis Signs
 Forgetting to Load a Package
 Forgetting to Install a Package
 A Dataset in a Loaded Package Is Not Found
 Leaving Out a Comma
 CopyandPaste Error
 Directory Problems—Cannot Load a Saved File
 Missing File Extension
 Do Not Assume That All Packages Use the Same Argument Abbreviations
 Outdated Packages/Package Incompatibility

Appendix R Functions Introduced in This Book
 Data Input/Output
 Datasets
 Graphical Functions 1—Creates Graph
 Graphical Functions 2—Adds Features to Existing Graph
 Miscellaneous
 Packages
 Statistics
 UserDefined Functions and Scripts
 Workspace and Directories
