ggplot
What is ggplot2?
ggplot, more precisely known as ggplot2, is a data visualization package for the R programming language. It implements Leland Wilkinson's Grammar of Graphics, a system that breaks charts into layers such as data, scales, and geometry rather than treating each chart type as a one-off function.
R programmer Hadley Wickham created ggplot2 in 2005. It remains one of the most widely used R packages for data visualization, in large part because its default chart settings look polished without extra styling work.
Why ggplot matters
ggplot2 lets you describe a full chart declaratively: specify what data maps to which visual elements, and let the package handle rendering. Base R graphics work the opposite way, sentence by sentence: set up a layout, plot a variable, add a title, then repeat for the next variable.
That difference matters for teams that iterate on visualizations quickly. Adding, removing, or changing a chart element in ggplot2 means adjusting one layer instead of rewriting the whole plotting sequence, which keeps exploratory analysis fast even as the questions being asked keep changing.
Core components of ggplot2
ggplot2 builds charts from layered components:
- Data and aesthetic mappings: which variables map to which visual properties, such as the x-axis, y-axis, or color
- Geometric objects: the type of visual representation, such as bars, points, or lines
- Scales and themes: how mapped values translate to visible output, such as axis ranges and color palettes
A simple example plots a bar chart from a dataset of programmers and their downloads:
ggplot(dataset, aes(x = Programmer, y = Downloads)) + geom_col()
For spatial plotting, ggmap extends ggplot2 to draw over downloaded map tiles.
ggplot2 can be installed on its own, or as part of the tidyverse collection:
install.packages("ggplot2")
install.packages("tidyverse")
ggplot2 code also runs inside managed environments such as Domino's AI workbench, for teams that need reproducible R setups.
FAQ
What does ggplot stand for?
"gg" stands for Grammar of Graphics, the visualization theory the package implements. "ggplot" is shorthand people use for the R package ggplot2.
Is ggplot the same as ggplot2?
In current usage, yes. "ggplot" is the common shorthand; "ggplot2" is the package's formal name and the one you'll see in documentation and installation commands.
Is ggplot2 part of the tidyverse?
Yes. ggplot2 is one of the core tidyverse packages, along with tools like dplyr for data wrangling. Installing the tidyverse installs ggplot2 along with it.
What is ggplot2 used for?
ggplot2 is used to create statistical charts and visualizations in R, from simple bar charts and scatterplots to complex layered graphics, at a higher level of abstraction than base R plotting.