Create plots with ggplot2

Teppo Valtonen · 2023

The Tidyverse package ggplot2 is a comprehensive and flexible framework for visualizing data in R. It is based on the Grammar of Graphics, that allows you to build plots, layer by layer, from independent components. The grammar dictates how to map variables to the aesthetic attributes (colour, shape, size) of geometric objects (points, lines, bars). ggplot2 has five mapping components. 1. Layer: a collection of geometric elements ( “geom” ), such as points, lines, polygons, and statistical transformations ( “stat” ), that summarise the data, for example, binning and counting observations to create a histogram, or fitting a linear model. 2. Scale: a mapping between values in the data to aesthetics, such as colour, shape or size; scales also draw the legend and axes. 3. Coord: a coordinate system that describes how data coordinates are mapped to the plane of the graphic; it affects also axes and gridlines. 4. Facet: a specification for plotting subsets of the same variables, often with at least one same axis. 5. Theme: a collection of layout elements, such as the font size and background colour. You can modify all attributes, objects and elements of a plot.

Read the paper · More papers on PaperTik