Chapter 2 What is ggplot2?

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.

  • To get more information about this special packages, you can visit http://ggplot2.org/

  • Also, there are many videos, books and pages related to this packages.

The ggplot2 implies “Grammar of Graphics” which believes in the principle that a plot can be split into the following basic parts -

Plot = data + Aesthetics + Geometry

  • data refers to a data frame (dataset).

  • Aesthetics indicates x and y variables. It is also used to tell R how data are displayed in a plot, e.g. color, size and shape of points etc.

  • Geometry refers to the type of graphics (bar chart, histogram, box plot, line plot, density plot, dot plot etc.)

Why ggplot2 is better?

  • Excellent themes can be created with a single command.

  • Its colors are nicer and more pretty than the usual graphics.

  • Easy to visualize data with multiple variables.

  • Provides a platform to create simple graphs providing plethora of information.

Before starting class, please load the following libraries

install.packages(c("ggplot2","gcookbook","ggalt","leaflet")) #to install more than one library at the same time.

#ggplot2 is for the graphical representation
#gcookbook is for some special data sets