ggplot is a graphic library that follows the grammar of graphics.
charts are made of :
ggplot(df, aes(x, y, <other aesthetics>))
will define as default for all layers
Without any argument, ggplot initializes a skeleton ggplot object which is fleshed out as layers are added.
ggplot() is typically used to construct a plot incrementally, using the + operator to add layers to the existing ggplot object. This is advantageous in that the code is explicit about which layers are added and the order in which they are added.
Plot = ggplot(data, mapping) +
layer(
stat = "",
geom = "",
position = "",
geom_parms = list(),
stat_params = list(),
)
where:
Example: Layers are created with the layer function but usually they are created directly through the shortcut functions geom_* (geom_point is a layer with a point geom) or stat_*)
d <- ggplot(diamonds, aes(x=carat, y=price))
d + geom_point()
d + geom_point(aes(colour = carat))
ggplot(diamonds) + geom_histogram(aes(x=price))
where: