Get startedGet started for free

Setting a dummy aesthetic

In the last chapter you saw that all the visible aesthetics can serve as attributes and aesthetics, but I very conveniently left out x and y. That's because although you can make univariate plots (such as histograms, which you'll get to in the next chapter), a y-axis will always be provided, even if you didn't ask for it.

You can make univariate plots in ggplot2, but you will need to add a fake y axis by mapping y to zero.

When using setting y-axis limits, you can specify the limits as separate arguments, or as a single numeric vector. That is, ylim(lo, hi) or ylim(c(lo, hi)).

This exercise is part of the course

Introduction to Data Visualization with ggplot2

View Course

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Plot 0 vs. mpg
___ +
  # Add jitter 
  ___(___)
Edit and Run Code