เริ่มต้นใช้งานเริ่มต้นใช้งานได้ฟรี

การตั้งค่าธีม

การนำธีมเดิมมาใช้ซ้ำกับหลายกราฟช่วยให้รูปแบบภาพดูสอดคล้องกัน ซึ่งทำได้หลายวิธี

  1. กำหนดธีมให้กับตัวแปร แล้วเพิ่มลงในแต่ละกราฟ
  2. ตั้งธีมเป็นค่าเริ่มต้นด้วย theme_set()

แนวทางที่ดีซึ่งจะใช้ที่นี่คือ เริ่มจากธีมสำเร็จรูปแล้วปรับแต่งต่อ

plt_prop_unemployed_over_time พร้อมใช้งานแล้ว ธีมที่สร้างไว้ก่อนหน้านี้แสดงอยู่ในโค้ดตัวอย่าง

แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร

การแสดงผลข้อมูลด้วย ggplot2 เบื้องต้น

ดูคอร์ส

แบบฝึกหัดเชิงโต้ตอบแบบลงมือทำ

ลองทำแบบฝึกหัดนี้โดยเติมโค้ดตัวอย่างนี้ให้สมบูรณ์

# Save the theme as theme_recession
___ <- theme(
  rect = element_rect(fill = "grey92"),
  legend.key = element_rect(color = NA),
  axis.ticks = element_blank(),
  panel.grid = element_blank(),
  panel.grid.major.y = element_line(color = "white", size = 0.5, linetype = "dotted"),
  axis.text = element_text(color = "grey25"),
  plot.title = element_text(face = "italic", size = 16),
  legend.position = c(0.6, 0.1)
)

# Combine the Tufte theme with theme_recession
theme_tufte_recession <- ___

# Add the Tufte recession theme to the plot
___
แก้ไขและรันโค้ด