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

Connected

Exercise

Modifying whitespace

Whitespace means all the non-visible margins and spacing in the plot.

To set a single whitespace value, use unit(x, unit), where x is the amount and unit is the unit of measure.

Borders require you to set 4 positions, so use margin(top, right, bottom, left, unit). To remember the margin order, think TRouBLe.

The default unit is "pt" (points), which scales well with text. Other options include "cm", "in" (inches) and "lines" (of text).

plt_mpg_vs_wt_by_cyl is available. The panel and legend are wrapped in blue boxes so you can see how they change.

Instructions 1/4

undefined XP
  • 1
    • Give the axis tick length, axis.ticks.length, a unit of 2 "lines".
  • 2
    • Give the legend key size, legend.key.size, a unit of 3 centimeters ("cm").
  • 3
    • Set the legend.margin to 20 points ("pt") on the top, 30 pts on the right, 40 pts on the bottom, and 50 pts on the left.
  • 4
    • Set the plot margin, plot.margin, to 10, 30, 50, and 70 millimeters ("mm").