Scales: Defining How Data is Mapped to Aesthetics

Scales determine how raw data gets converted into colors, sizes, axes, and more. They’re the link between data values and their visual representation.

From color palettes to log transforms, you’ll learn how to take full control over the look and feel of your plots — without changing the data itself.

Members only9 minutes read

🧠 Map ’n’ Shape

When you specify an aesthetic like x = wday or color = cyl, you’re telling ggplot2 what variable to map to the respective aesthetic — andggplot2 encodes them accordingly.

But what defines how the values of that column are translated into visual properties? That’s where scales come in.

Each aesthetic (like color, size, or x) has a corresponding scale that controls how the data is visually represented.

Together, aesthetics and scales form a two-part system:

The names of scale functions (and there are a ton!) always reference the respective aesthetic and often a specific type of data or behavior:

scale_[aesthetic]_[type]()

Feels abstract? Let’s look at a few examples:

Based on the mapping you’ve specified, ggplot2 applies appropriate default scales (if you don't specify them yourself) — behind the scenes, to make your plot work:

🎚️ Controlling Scales

If you want to tweak how a scale behaves, you can simply modify its settings — or replace it with the scale_*() function that fits your needs.

Some common reasons to modify or replace a scale:

You don’t have to change the data to do any of this — it’s all handled by the scale_*() functions.

Most scale_*() functions have share some general arguments:

Oh no! 😱

It seems like you haven’t enrolled in the course yet!

Join many other students today and become the ggplot2 expert your company needs!


Or Login

← Previous

Coordinate Systems

Next →

Exporting Plots