by Jeon Lee on January 9, 2019

Basics

ggplot2 is based on the grammar of graphics, the idea that you can build every graph from the same few components: a data set, a set of geoms-visual marks that represent data points, and a coordinate system.

To display data values, map variables in the data set to aesthetic properties of the geom like size, color, and x and y locations.

Build a graph with qplot() or ggplot().

<Example of qplot()>

<Example of qplot()>

It creates a complete plot with given data, geom, and mappings. Supplies many useful defaults.

Add a new layer to a plot with a geom_() or stat_() function. Each provides a geom, a set of aesthetic mappings, and a default stat and position adjustment.

<Example of ggplot()>

<Example of ggplot()>

One variable plots

1. Continuous variable