Exercise

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)).

Instructions 1/2

undefined XP
  • 1
    • Using mtcars, plot 0 vs. mpg.
    • Make a scatter plot and add "jitter" to it.
  • 2

    Use ylim() to set the limits on the y-axis from -2 to 2.