8.1 Getting started

A ggplot graph needs at least 3 components:

  • Data: that is the source data that we want to represent.
  • Aesthetics mappings: they describe what will be visualized from data.
  • Geometrics: functions that represent what we see in the graph: lines, points, boxes etc. for example:
    • geom_point()
    • geom_lines()
    • geom_histogram()
    • geom_boxplot()
    • geom_bar()
    • geom_smooth()
    • geom_tiles()

The base structure is the following:

ggplot(<DATA>, <AESTHETICS>) + <GEOMETRICS>

For example if we want to represent column1 (on the x axis) and column2 (on the y axis) of data as points, we would use the following structure:

ggplot(data=dataframe, mapping=aes(x=column1, y=column2)) + geom_point()

This will be our template as we explore different types of graphs.

We can add more layers to this base structure to customize the plot further, as we will see in the next examples.