Get startedGet started for free

Modifying theme elements

Many plot elements have multiple properties that can be set. For example, line elements in the plot such as axes and gridlines have a color, a thickness (size), and a line type (solid line, dashed, or dotted). To set the style of a line, you use element_line(). For example, to make the axis lines into red, dashed lines, you would use the following.

p + theme(axis.line = element_line(color = "red", linetype = "dashed"))

Similarly, element_rect() changes rectangles and element_text() changes text. You can remove a plot element using element_blank().

plt_prop_unemployed_over_time is available.

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.

plt_prop_unemployed_over_time +
  theme(
    # For all rectangles, set the fill color to grey92
    ___ = ___(___ = ___),
    # For the legend key, turn off the outline
    ___
  )
Edit and Run Code