

To demonstrate how the function ggplot() works, we’ll draw a scatter plot. Geometry: the type of plots ( histogram, boxplot, line, density, dotplot, bar, …).Aesthetics: used to specify x and y variables, color, size, shape, ….Recall that, the concept of ggplot divides a plot into three different fundamental parts: plot = data + Aesthetics + geometry. This section describes briefly how to use the function ggplot(). The more powerful and flexible function to build plots piece by piece: ggplot().The quick and easy-to-use function: qplot().Many examples of code and graphics are provided.Īs mentioned above, there are two main functions in ggplot2 package for generating graphics: This document describes how to create and customize different types of graphs using ggplot2. ggsave(“plot.png”, width = 5, height = 5), which saves the last plot in the current working directory.last_plot(), which returns the last plot to be modified.

The generated plot can be kept as a variable and then printed at any time using the function print().Īfter creating plots, two other important functions are:

The gg in ggplot2 means Grammar of Graphics, a graphic concept which describes plots by using a “grammar”.Īccording to ggplot2 concept, a plot can be divided into different fundamental parts : Plot = data + Aesthetics + Geometry. Ggplot2 is a powerful and a flexible R package, implemented by Hadley Wickham, for producing elegant graphics.
