Graphic Systems in R

If you want to plot a graph in R for your own consumption, it is pretty easy and you can generally do it with a few lines of code. However, if you are creating the graph for others consumption and want full control over all aspects of the graph, it will require some effort. The standard R distribution comes prepackages with powerful graphing capabilities. There are three in-built graphic packages, namely, Base, Grid and Lattice graphic packages. Apart from these three, there is also ggplot2, another popular graphic package for R.

Base Graphics

Base graphics is the oldest and original graphic system built for R. This is the core plotting system and contains functions including plot()hist()boxplot() and many others. The code for base graphics is in the graphics package, which is loaded by default when you start R.

Grid

Grid is an alternative graphic system which was added to R at a later stage. It implements a completely different graphic system independent of the core graphics package. It is more like a framework and doesn't produce complete graphics by itself. For this reason, we seldom call functions from the grid package directly.

Lattice

Lattice is an add-on graphic package that contains code for producing Trellis graphics - graphs that display a variable or the relationship between variables, conditioned on one or more other variables. It includes functions like xyplot()bwplot()levelplot()histogram(). Lattice graphics in R make use of grid graphics. This is incompatible with Base graphics package.

ggplot2

ggplot2 is a system for 'declaratively' creating graphics, based on "The Grammar of Graphics". You provide the data, tell 'ggplot2' how to map variables to aesthetics, what graphical primitives to use, and it takes care of the details. Here is the statement of purpose for the ggplo2 package - ggplot2 is a plotting system for R, based on the grammar of graphics, which tries to take the good parts of base and lattice graphics and none of the bad parts. It takes care of many of the fiddly details that make plotting a hassle (like drawing legends) as well as providing a powerful model of graphics that makes it easy to produce complex multi-layered graphics.

Base graphics are used most commonly and are a very powerful system for creating 2-D graphics. In this course, we will focus on the Base graphics system and ggplot2.

Related Downloads

Data Science in Finance: 9-Book Bundle

Data Science in Finance Book Bundle

Master R and Python for financial data science with our comprehensive bundle of 9 ebooks.

What's Included:

  • Getting Started with R
  • R Programming for Data Science
  • Data Visualization with R
  • Financial Time Series Analysis with R
  • Quantitative Trading Strategies with R
  • Derivatives with R
  • Credit Risk Modelling With R
  • Python for Data Science
  • Machine Learning in Finance using Python

Each book includes PDFs, explanations, instructions, data files, and R code for all examples.

Get the Bundle for $39 (Regular $57)
JOIN 30,000 DATA PROFESSIONALS

Free Guides - Getting Started with R and Python

Enter your name and email address below and we will email you the guides for R programming and Python.

Data Science in Finance: 9-Book Bundle

Data Science in Finance Book Bundle

Master R and Python for financial data science with our comprehensive bundle of 9 ebooks.

What's Included:

  • Getting Started with R
  • R Programming for Data Science
  • Data Visualization with R
  • Financial Time Series Analysis with R
  • Quantitative Trading Strategies with R
  • Derivatives with R
  • Credit Risk Modelling With R
  • Python for Data Science
  • Machine Learning in Finance using Python

Each book comes with PDFs, detailed explanations, step-by-step instructions, data files, and complete downloadable R code for all examples.