6 Brief overview of ggplots2 package

All ggplot functions must have at least three components:

  • data frame: data associated with the plot.
  • geom: to determine the type of geometric shape used to display the data, such as line, bar, point, or area. Note that you can use different data in different geoms by
  • aes: to determine how variables in the data are mapped to visual properties (aesthetics) of geoms. This can include x position, y position, color, shape, fill, and size.
  • If the aes statement is included in the ggplot command, the mapping will be available to any geoms used
  • If you need a variable mapped to just a specific geom, you can include it in an aes mapping for a specific geom. (You can also do something similar with the data option if you need to plot multiple data sources on the same display. However, it is generally better to think about structuring your dataset )