8.1 Base structure

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. What are you trying to show?
  • 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 can 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 and components to this base structure to customize the plot: we will see examples throughout this course.