開始使用免費開始

變更背景顏色並加入邊界

theme 函式呼叫中加入更多引數,進一步自訂圖形外觀。 你可以接續使用上一題建立的 ilo_plot 物件。

本練習屬於課程

在 Tidyverse 中以資料溝通

檢視課程

練習說明

  • 將整體圖形背景顏色改為 "gray95"
    • 這次需要使用 element_text 以外的函式──專門用於長方形圖形元素。回看影片確認是哪一個。
  • 為圖形加入邊界(margins):上、下各 5 mm,左、右各 10 mm。
  • 邊界需要依以下順序指定:上、右、下、左。

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

ilo_plot +
  # "theme" calls can be stacked upon each other, so this is already the third call of "theme"
  theme(
    plot.background = ___(fill = ___),
    plot.margin = unit(c(___, ___, ___, ___), units = "mm")
  )
編輯並執行程式碼