i

R Programming Complete Tutorial

Ggplot2 Structure

ggplot is a data visualization package for the statistical programming language R.  Basically; it is a system for declaratively creating graphics based on the grammar of graphics. We need to provide the details, tell ggplot2 how to map aesthetic variables, what graphical primitives to use, and take care of the information.

ggplot works with the data frames and not individual vectors.

We are now going to discuss the structure of the ggplot in detail. We can divide a plot into three different fundamental parts:

The first one is Data, where we attach our Data frame. The second one is Aesthetics, which is used to indicate X and Y variables. It can also be used to control the color, the size, or the shape of points. And finally, Geometry corresponds to the type of graphics like Histogram, box plot, line plot, and many others.

Example: