開始使用免費開始

把新的主題函式套用到圖上

當你建立好自己的 theme_ilo() 函式後,就該把它套用到圖形物件上了。影片中你看到可以把多個 theme() 呼叫串接在一起。你將利用這點,再加上一個 theme() 呼叫,來調整分面圖一些特別的設定。

本練習屬於課程

在 Tidyverse 中以資料溝通

檢視課程

練習說明

  • 從現在開始,你可以把 theme_ilo() 加到任何想要的圖形物件上。試試看!覆寫 ilo_plot 變數,讓 theme_ilo() 永久套用。
  • 把你自訂的主題函式再搭配更多的 theme() 呼叫,彈性調整進階圖的設定。
    • 為了達到這點,在 theme_ilo() 呼叫之後再加上一個 theme() 呼叫。
    • 使用 strip.background 參數,把分面標籤背景的 fill 改為 "gray60"color 改為 "gray95"
    • 把分面標籤文字的 color 改為 "white"

動手互動練習

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

# Apply your theme function (dont't forget to call it with parentheses!)
ilo_plot <- ilo_plot +
  ___

# Examine ilo_plot
ilo_plot

ilo_plot +
  # Add another theme call
  ___(
    # Change the background fill and color
    strip.background = element_rect(___, ___),
    # Change the color of the text
    strip.text = element_text(___)
  )
編輯並執行程式碼