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
aesstatement is included in theggplotcommand, the mapping will be available to anygeoms used - If you need a variable mapped to just a specific
geom, you can include it in anaesmapping for a specific geom. (You can also do something similar with thedataoption if you need to plot multiple data sources on the same display. However, it is generally better to think about structuring your dataset )