Using ggplot2 package in R Programming
ggplot2 also termed as Grammar of Graphics is a free, opensource, and easy to use visualization package widely used in R. It is the most powerful visualization package written by Hadley Wickham.
It includes several layers on which it is governed. The layers are as follows:
Building Blocks of layers
Layers with variables of interest are as follows:
- Aesthetics: x-axis, y-axis, color, fill, size, labels, alpha, shape, line width, line type
- Geometrics: point, line, histogram, bar, boxplot
- Facets: Columns, rows
- Statistics: Binning, smoothing, descriptive, intermediate
- Coordinates: Cartesian, fixed, polar, limits
- Themes: Non-data link
mtcars(motor trend car road test) comprise fuel consumption and 10 aspects of automobile design and performance for 32 automobiles and come pre-installed with dplyr package in R.
Performing ggplot2 on dataset
We devise visualizations on mtcars dataset which includes 32 car brands and 11 attributes using ggplot2 layers.
- Geometric layer – Adding Size
- Geometric layer – Adding color and shape
- Geometric layer – Histogram plot
- Facet layer – Separate rows according to transmission type
- Facet layer – Separate columns according to cylinders
- Statistics Layer
- Coordinates layer: Control plot dimensions
- Coord_cartesian() to proper zoom in
- Theme layer – element_rect() function
- Theme layer
ggplot2 provides various types of visualizations. More parameters can be used included in the package as the package gives greater control over the visualizations of data. Many packages can integrate with the ggplot2 package to make the visualizations interactive and animated.