Get startedGet started for free

Visible aesthetics

1. Visible aesthetics

In this section we'll explore aesthetics, and understand how they are distinct from attributes.

2. Mapping onto the X and Y axes

In ggplot2, the mapping of aesthetics elements is a key concept to master. So what do we mean by mapping? This becomes clear when we understand that our beloved X and Y axes on a straightforward scatter plot are aesthetics. They define the position of dots on a common scale, like this example we saw in the previous chapter. The sepal length is mapped onto the X axis and the sepal width is mapped onto the Y axis. Here, we'll focus on the most common visual aesthetics and but we'll encounter more throughout the courses. When making multivariate plots we'll use aesthetics appropriately to maximize the number of variables we can add to a plot.

3. Mapping onto color

For example, the variable Species can be mapped onto the color aesthetic, which colors the points according to the species from which they came.

4. Mapping onto the color aesthetic

That is, we map a variable from our dataframe onto one of the visible aesthetics. We call a column in our dataframe to be mapped onto a visible aesthetic. That's why we made such a big deal about data structure earlier. Each mapped variable is its own column variable in the data frame.

5. Mapping onto the color aesthetic

Importantly, we call aesthetics in the aes function. We could have also called aesthetics in the geom layer

6. Mapping onto the color aesthetic in geom

as shown here, and get the same result. This is typically only done if we don't want all layers to inherit the same aesthetics or we're mixing different data sources. In general, try to keep your data and aesthetics layer in the same ggplot function definition.

7. Typical visible aesthetics

In addition to the X and Y axes and color, typical visible aesthetics include

8. Typical visible aesthetics

fill, which is distinct from

9. Typical visible aesthetics

color in that color usually, but not always, refers to the outline of a shape.

10. Typical visible aesthetics

Size adjusts the area or radius of points, the thickness of lines and the font size of text.

11. Typical visible aesthetics

alpha refers to alpha-blending, which adjusts the transparency of a shape.

12. Typical visible aesthetics

line type refers to the dash pattern of a line and

13. Typical visible aesthetics

labels are direct labels of an item, directly on the plot. Like printing an item's name on a scatter plot instead of just drawing a point. Direct labeling of points is an extension of axis labels for categorical data in that they are unambiguous, and

14. Typical visible aesthetics

Shape refers to the shape of a point. Many of these aesthetics function as both aesthetic mappings as well as attributes, and one of the most common mistakes beginners make is confusing the two or overwriting aesthetic mappings with fixed attributes. Our goal here is to not only show you how to use them correctly but appropriately for the plot's type and purpose. Just like our two main variable types, there are visible aesthetics for continuous and categorical data which we'll explore in the next video,

15. Let's Practice

for now, let's head over to the exercises and take a look at how aesthetics work.

Create Your Free Account

or

By continuing, you accept our Terms of Use, our Privacy Policy and that your data is stored in the USA.