1. Learn
  2. /
  3. Courses
  4. /
  5. Introduction to Data Visualization with ggplot2

Exercise

Moving the legend

Let's wrap up this course by making a publication-ready plot communicating a clear message.

To change stylistic elements of a plot, call theme() and set plot properties to a new value. For example, the following changes the legend position.

p + theme(legend.position = new_value)

Here, the new value can be

  • "top", "bottom", "left", or "right'": place it at that side of the plot.
  • "none": don't draw it.
  • c(x, y): c(0, 0) means the bottom-left and c(1, 1) means the top-right.

Let's revisit the recession period line plot (assigned to plt_prop_unemployed_over_time).

Instructions 1/3

undefined XP
  • 1
    • Update the plot to remove the legend.
    • Look at the changes in the plot.
  • 2
    • Update the plot to position the legend at the bottom of the plot.
    • Look at the changes in the plot.
  • 3
    • Position the legend inside the plot, with x-position 0.6 and y-position 0.1.
    • Look at the changes in the plot.