0%

Book Description

Extend your capabilities with R and learn to present data in graphical form. This comprehensive guide is designed to help you produce professional quality graphs by providing practical exercises for you to complete.

  • Learn to draw any type of graph or visual data representation in R
  • Filled with practical tips and techniques for creating any type of graph you need; not just theoretical explanations
  • All examples are accompanied with the corresponding graph images, so you know what the results look like
  • Each recipe is independent and contains the complete explanation and code to perform the task as efficiently as possible

In Detail

With more than two million users worldwide, R is one of the most popular open source projects. It is a free and robust statistical programming environment with very powerful graphical capabilities. Analyzing and visualizing data with R is a necessary skill for anyone doing any kind of statistical analysis, and this book will help you do just that in the easiest and most efficient way possible.

Unlike other books on R, this book takes a practical, hands-on approach and you dive straight into creating graphs in R right from the very first page.You want to harness the power of this open source programming language to visually present and analyze your data in the best way possible - and this book will show you how.

The R Graph Cookbook takes a practical approach to teaching how to create effective and useful graphs using R. This practical guide begins by teaching you how to make basic graphs in R and progresses through subsequent dedicated chapters about each graph type in depth. It will demystify a lot of difficult and confusing R functions and parameters and enable you to construct and modify data graphics to suit your analysis, presentation, and publication needs.

You will learn all about making graphics such as scatter plots, line graphs, bar charts, pie charts, dot plots, heat maps, histograms and box plots. In addition, there are detailed recipes on making various combinations and advanced versions of these graphs. Dedicated chapters on polishing and finalizing graphs will enable you to produce professional-quality graphs for presentation and publication. With R Graph Cookbook in hand, making graphs in R has never been easier.

Table of Contents

  1. R Graphs Cookbook
    1. R Graphs Cookbook
    2. Credits
    3. About the Author
    4. About the Reviewers
    5. www.PacktPub.com
      1. Support files, eBooks, discount offers, and more
        1. Why Subscribe?
        2. Free Access for Packt account holders
    6. Preface
      1. What this book covers
      2. What you need for this book
      3. Who this book is for
      4. Conventions
      5. Reader feedback
      6. Customer support
        1. Errata
        2. Piracy
        3. Questions
    7. 1. Basic Graph Functions
      1. Introduction
      2. Creating scatter plots
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. A note on R's inbuilt datasets
        5. See also
      3. Creating line graphs
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
        5. See also
      4. Creating bar charts
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
        5. See also
      5. Creating histograms and density plots
        1. How to do it...
        2. How it works...
        3. There's more...
        4. See also
      6. Creating box plots
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
        5. See also
      7. Adjusting X and Y axes limits
        1. How to do it...
        2. How it works...
        3. There's more...
        4. See also
      8. Creating heat maps
        1. How to do it...
        2. How it works...
        3. There's more...
        4. See also
      9. Creating pairs plots
        1. How to do it...
        2. How it works...
        3. There's more...
        4. See also
      10. Creating multiple plot matrix layouts
        1. How to do it...
        2. How it works...
        3. There's more...
        4. See also
      11. Adding and formatting legends
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
        5. See also
      12. Creating graphs with maps
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
        5. See also
      13. Saving and exporting graphs
        1. How to do it...
        2. How it works...
        3. There's more...
        4. See also
    8. 2. Beyond the Basics: Adjusting Key Parameters
      1. Introduction
      2. Setting colors of points, lines, and bars
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
        5. See also
      3. Setting plot background colors
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
      4. Setting colors for text elements: axis annotations, labels, plot titles, and legends
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
      5. Choosing color combinations and palettes
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
        5. See also
      6. Setting fonts for annotations and titles
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
        5. See also
      7. Choosing plotting point symbol styles and sizes
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
        5. See also
      8. Choosing line styles and width
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. See also
      9. Choosing box styles
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
      10. Adjusting axis annotations and tick marks
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
        5. See also
      11. Formatting log axes
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
      12. Setting graph margins and dimensions
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. See also
    9. 3. Creating Scatter Plots
      1. Introduction
      2. Grouping data points within a scatter plot
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
        5. See also
      3. Highlighting grouped data points by size and symbol type
        1. Getting ready
        2. How to do it...
        3. How it works...
      4. Labelling data points
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
      5. Correlation matrix using pairs plot
        1. Getting ready
        2. How to do it...
        3. How it works...
      6. Adding error bars
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
      7. Using jitter to distinguish closely packed data points
        1. Getting ready
        2. How to do it...
        3. How it works...
      8. Adding linear model lines
        1. Getting ready
        2. How to do it...
        3. How it works...
      9. Adding non-linear model curves
        1. Getting ready
        2. How to do it...
        3. How it works...
      10. Adding non-parametric model curves with lowess
        1. Getting ready
        2. How to do it...
        3. How it works...
      11. Making three-dimensional scatter plots
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
      12. How to make Quantile-Quantile plots
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
      13. Displaying data density on axes
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
      14. Making scatter plots with smoothed density representation
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
    10. 4. Creating Line Graphs and Time Series Charts
      1. Introduction
      2. Adding customized legends for multiple line graphs
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
        5. See also
      3. Using margin labels instead of legends for multiple line graphs
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
      4. Adding horizontal and vertical grid lines
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
        5. See also
      5. Adding marker lines at specific X and Y values
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
      6. Creating sparklines
        1. Getting ready
        2. How to do it...
        3. How it works...
      7. Plotting functions of a variable in a dataset
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
      8. Formatting time series data for plotting
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
      9. Plotting date and time on the X axis
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
      10. Annotating axis labels in different human readable time formats
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
      11. Adding vertical markers to indicate specific time events
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
      12. Plotting data with varying time averaging periods
        1. Getting ready
        2. How to do it...
        3. How it works...
      13. Creating stock charts
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
    11. 5. Creating Bar, Dot, and Pie Charts
      1. Introduction
      2. Creating bar charts with more than one factor variable
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. See also
      3. Creating stacked bar charts
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
      4. Adjusting the orientation of bars—horizontal and vertical
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
      5. Adjusting bar widths, spacing, colors, and borders
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
      6. Displaying values on top of or next to the bars
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
        5. See also
      7. Placing labels inside bars
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
      8. Creating bar charts with vertical error bars
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
      9. Modifying dot charts by grouping variables
        1. Getting ready
        2. How to do it...
        3. How it works...
      10. Making better readable pie charts with clockwise-ordered slices
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. See also
      11. Labelling a pie chart with percentage values for each slice
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
        5. See also
      12. Adding a legend to a pie chart
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
    12. 6. Creating Histograms
      1. Introduction
      2. Visualizing distributions as count frequencies or probability densities
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
      3. Setting bin size and number of breaks
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
      4. Adjusting histogram styles: bar colors, borders, and axes
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
      5. Overlaying density line over a histogram
        1. Getting ready
        2. How to do it...
        3. How it works...
      6. Multiple histograms along the diagonal of a pairs plot
        1. Getting ready
        2. How to do it...
        3. How it works...
      7. Histograms in the margins of line and scatter plots
        1. Getting ready
        2. How to do it...
        3. How it works...
    13. 7. Creating Box and Whisker Plots
      1. Introduction
      2. Creating box plots with narrow boxes for a small number of variables
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
        5. See also
      3. Grouping over a variable
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
        5. See also
      4. Varying box widths by number of observations
        1. Getting ready
        2. How to do it...
        3. How it works...
      5. Creating box plots with notches
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
      6. Including or excluding outliers
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. See also
      7. Creating horizontal box plots
        1. Getting ready
        2. How to do it...
        3. How it works...
      8. Changing box styling
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
      9. Adjusting the extent of plot whiskers outside the box
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
      10. Showing the number of observations
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
      11. Splitting a variable at arbitrary values into subsets
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
    14. 8. Creating Heat Maps and Contour Plots
      1. Introduction
      2. Creating heat maps of single Z variable with scale
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
        5. See also
      3. Creating correlation heat maps
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
      4. Summarizing multivariate data in a heat map
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
      5. Creating contour plots
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
        5. See also
      6. Creating filled contour plots
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
        5. See also
      7. Creating three-dimensional surface plots
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
      8. Visualizing time series as calendar heat maps
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
    15. 9. Creating Maps
      1. Introduction
      2. Plotting global data by countries on a world map
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
        5. See also
      3. Creating graphs with regional maps
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
      4. Plotting data on Google maps
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
        5. See also
      5. Creating and reading KML data
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. See also
      6. Working with ESRI shapefiles
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
    16. 10. Finalizing graphs for publications and presentations
      1. Introduction
      2. Exporting graphs in high resolution image formats: PNG, JPEG, BMP, TIFF
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
        5. See also
      3. Exporting graphs in vector formats: SVG, PDF, PS
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
      4. Adding mathematical and scientific notations (typesetting)
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
      5. Adding text descriptions to graphs
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
      6. Using graph templates
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
      7. Choosing font families and styles under Windows, Mac OS X, and Linux
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
        5. See also
      8. Choosing fonts for PostScripts and PDFs
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...