concept aes() in category R

appears as: es()
R in Action, Third Edition

This is an excerpt from Manning's book R in Action, Third Edition.

  • the mapping of the variables to visual properties of the graph. The mappings are placed in an aes() function (which stands for aesthetics or "something you can see").
  • Exploring Data with R

    This is an excerpt from Manning's book Exploring Data with R.

    Let’s describe a simple scatterplot with the dmd variables carats (the weight of the diamond) and price (the price in US dollars). The very first instruction we’ll provide is a ggplot() function call (Listing 3.1). This requires data (we’ll use the dmd table as data), and, it also has an argument called mapping. We’ll map carats to the x axis and price to the y axis, and this will be wrapped up inside the aes() object (aes stands for aesthetics). This last part implies that the axes to which data values are bound are aesthetic properties, and that’s really how the grammar of graphics sees it (along with other aesthetic properties like the shape and color of marks). After running the code chunk, we’ll get the plot shown as Figure 3.1.

  • To get all points in red, one must ensure that color = "red" is given in geom_point() and that it’s not inside aes(). This is the plotting code: ggplot(data = dmd, mapping = aes(x = carats, y = price)) +
  • geom_point(color = "red")
  • The difference lies in how we are using the color argument. In statement (1) color is used inside of aes() and so we are allowed to map a variable to it (each data point’s color varies according to the value of depth). In statement (2) we are using color outside of aes() and providing a single value of "blue" thus making all of the plotted data points appear blue.
  • When using color outside of aes() we can provide a color name (e.g., "red", "blue", "green") or a hexadecimal color code (e.g., "#EFEFEF", etc.).