ggplot2 (R)
ggplot2 is R's most popular plotting package, built on the 'grammar of graphics'. You build plots in layers — data, aesthetic mappings, and geometric shapes — combined with the + operator.
R
ggplot2 takes a layered, declarative approach: you start with ggplot(data, aes(...)) to map variables to visual properties (x, y, color, size), then add geom_ layers (geom_point, geom_line, geom_bar, etc.) and optional scales, facets, and themes — all joined with +. This grammar makes complex, publication-quality graphics composable from simple parts.
Because aesthetics map data columns to visual channels, a single change (say, color = species) automatically splits and legends your plot. faceting (facet_wrap) creates small-multiple panels, and themes control the overall look. It expects tidy data — one observation per row — which is why it pairs so well with dplyr and tibbles.
ggplot2 is part of the tidyverse and the de facto standard for data visualization in R. Its consistency means once you learn the grammar, you can build almost any static chart by combining the same building blocks.
Syntax
library(ggplot2)
ggplot(df, aes(x, y)) + geom_point()Examples
R — Builds a scatter plot of weight vs mpg, colored by cylinder count.
library(ggplot2)
ggplot(mtcars, aes(x = wt, y = mpg, color = factor(cyl))) +
geom_point() +
labs(title = "Weight vs MPG")