You are previewing Graphing Data with R.
O'Reilly logo
Graphing Data with R

Book Description

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.

Table of Contents

  1. Preface
    1. Who Is This Book For?
      1. Why R?
      2. How to Use This Book
    2. Conventions Used in This Book
    3. Using Code Examples
    4. Safari® Books Online
    5. How to Contact Us
    6. Acknowledgments
  2. I. Getting Started with R
  3. 1. R Basics
    1. Downloading the Software
    2. Try Some Simple Tasks
    3. User Interface
    4. Installing a Package: A GUI Interface
    5. Data Structures
    6. Sample Datasets
    7. The Working Directory
    8. Putting Data into R
      1. Typing into a Command Line
      2. Using the Data Editor
      3. Reading from an External File
    9. Sourcing a Script
    10. User-Written Functions
    11. A Taste of Things to Come
      1. Exercise 1-4
  4. 2. An Overview of R Graphics
    1. Exporting a Graph
    2. Exploratory Graphs and Presentation Graphs
    3. Graphics Systems in R
      1. Base Graphics and grid
      2. lattice
      3. ggplot2
      4. Special Applications/Graphs Incorporated into Packages
      5. User-Written Graphic Functions
  5. II. Single-Variable Graphs
  6. 3. Strip Charts
    1. A Simple Graph
    2. Data Can Be Beautiful
      1. Exercise 3-1
      2. Exercise 3-2
  7. 4. Dot Charts
    1. Basic Dot Chart
    2. Exercise 4-1
      1. Exercise 4-2
  8. 5. Box Plots
    1. The Box Plot
    2. Nimrod Again
    3. Making the Data Beautiful
      1. Exercise 5-1
      2. Exercise 5-2
  9. 6. Stem-and-Leaf Plots
    1. Basic Stem-and-Leaf Plot
    2. Exercise 6-1
      1. Exercise 6-2
  10. 7. Histograms
    1. Simple Histograms
    2. Histograms with a Second Variable
      1. Exercise 7-1
      2. Exercise 7-2
  11. 8. Kernel Density Plots
    1. Density Estimation
      1. Choosing a Bandwidth
      2. Comparing Two or More Density Plots
      3. A Background That Is Not White
    2. The Cumulative Distribution Function
      1. Exercise 8-1
      2. Exercise 8-2
  12. 9. Bar Plots (Bar Charts)
    1. Basic Bar Plot
    2. Spine Plot
    3. Bar Spacing and Orientation
      1. Exercise 9-1
      2. Exercise 9-2
  13. 10. Pie Charts
    1. Ordinary Pie Chart
    2. Fan Plot
      1. Exercise 10-1
      2. Exercise 10-2
  14. 11. Rug Plots
    1. The Rug Plot
    2. Exercise 11-1
  15. III. Two-Variable Graphs
  16. 12. Scatter Plots and Line Charts
    1. Basic Scatter Plots
    2. Line Charts
    3. Templates
    4. Enhanced Scatter Plots
      1. Exercise 12-1
      2. Exercise 12-2
  17. 13. High-Density Plots
    1. Working with Large Datasets
      1. Sunflower Plot
        1. Smooth Scatter Plot
          1. Exercise 13-1
  18. 14. The Bland-Altman Plot
    1. Assessing Measurement Reliability
      1. Exercise 14-1
      2. A Shorter Version of baplot()
  19. 15. QQ Plots
    1. Comparing Sets of Numbers
      1. Exercise 15-1
      2. Exercise 15-2
  20. IV. Multivariable Graphs
  21. 16. Scatter plot Matrices and Corrgrams
    1. Scatter plot Matrix
    2. Corrgram
    3. Generalized Pairs Matrix with Mixed Quantitative and Categorical Variables
      1. Exercise 16-1
  22. 17. Three-Dimensional Plots
    1. 3D Scatter plots
    2. False Color Plots
    3. Bubble Plots
      1. Exercise 17-1
      2. Exercise 17-2
  23. 18. Coplots (Conditioning Plots)
    1. The Coplot
    2. Exercise 18-1
  24. 19. Clustering: Dendrograms and Heat Maps
    1. Clustering
    2. Heat Maps
      1. Exercise 19-1
      2. Exercise 19-2
      3. Exercise 19-3
  25. 20. Mosaic Plots
    1. Graphing Categorical Data
      1. Exercise 20-1
  26. V. What Now?
  27. 21. Resources for Extending Your Knowledge of Things Graphical and R Fluency
    1. R Graphics
    2. General Principles of Graphics
    3. Learning More About R
    4. Statistics with R
      1. Exercise 21-1
  28. A. References
  29. B. R Colors
  30. C. The R Commander Graphical User Interface
  31. D. Packages Used/Referenced
  32. E. Importing Data from Outside of R
    1. Some Useful Internet Data Repositories
    2. Importing Data of Various Types into R
      1. CSV
      2. Statistical Packages (SPSS, SAS, Etc.)
      3. ASCII
      4. XML
      5. netCDF
      6. Web Scraping
  33. F. Solutions to Chapter Exercises
    1. Exercises 1-1 Through 1-4
    2. Exercise 3-1
    3. Exercise 3-2
    4. Exercise 4-1
    5. Exercise 4-2
    6. Exercise 5-1
    7. Exercise 5-2
    8. Exercise 6-1
    9. Exercise 6-2
    10. Exercise 7-1
    11. Exercise 8-1
    12. Exercise 8-2
    13. Exercise 9-1
    14. Exercise 9-2
    15. Exercise 10-1
    16. Exercise 10-2
    17. Exercise 11-1
    18. Exercise 12-1
    19. Exercise 12-2
    20. Exercise 13-1
    21. Exercise 14-1
    22. Exercise 15-1
    23. Exercise 15-2
    24. Exercise 16-1
    25. Exercise 17-1
    26. Exercise 17-2
    27. Exercise 18-1
    28. Exercise 19-1
    29. Exercise 19-2
    30. Exercise 19-3
    31. Exercise 20-1
    32. Exercise 21-1
  34. G. Troubleshooting: Why Doesn’t My Code Work?
    1. Misspelling
    2. Confusing Uppercase/Lowercase
    3. Too Few (or Too Many) Parenthesis Signs
    4. Forgetting to Load a Package
    5. Forgetting to Install a Package
    6. A Dataset in a Loaded Package Is Not Found
    7. Leaving Out a Comma
    8. Copy-and-Paste Error
    9. Directory Problems—Cannot Load a Saved File
    10. Missing File Extension
    11. Do Not Assume That All Packages Use the Same Argument Abbreviations
    12. Outdated Packages/Package Incompatibility
  35. H. R Functions Introduced in This Book
    1. Data Input/Output
    2. Datasets
    3. Graphical Functions 1—Creates Graph
    4. Graphical Functions 2—Adds Features to Existing Graph
    5. Miscellaneous
    6. Packages
    7. Statistics
    8. User-Defined Functions and Scripts
    9. Workspace and Directories
  36. Index