ggplot2 also termed as Grammer 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) comprises fuel consumption and 10 aspects of automobile design and performance for 32 automobiles and comes pre installed with
dplyr package in R.
Performing ggplot2 on dataset
We devise visualisations on
mtcars dataset which includes 32 car brands and 11 attributes using
- Geometric layer
- Geometric layer – Adding Size
- Geometric layer – Adding colour 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
- tidyr Package in R Programming
- dplyr Package in R Programming
- Shiny Package in R Programming
- Esquisse Package in R Programming
- Add Leading Zeros to the Elements of a Vector in R Programming - Using paste0() and sprintf() Function
- Plotting Graphs using Two Dimensional List in R Programming
- Social Network Analysis Using R Programming
- Add new Variables to a Data Frame using Existing Variables in R Programming - mutate() Function
- Add Color Between Two Points of Kernel Density Plot in R Programming - Using with() Function
- Transform the Scaled Matrix to its Original Form in R Programming - Using Matrix Computations
- Set Aspect Ratio of Scatter Plot and Bar Plot in R Programming - Using asp in plot() Function
- Time Series Analysis using ARIMA model in R Programming
- Time Series Analysis using Facebook Prophet in R Programming
- Plotting of Data using Generic plots in R Programming - plot() Function
- Regression using k-Nearest Neighbors in R Programming
- Visualize correlation matrix using correlogram in R Programming
- Visualize Correlation Matrix using symnum function in R Programming
- Building REST API using R Programming
- Accessing REST API using R Programming
- How to Include Factors in Regression using R Programming?
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.
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.